22

I use resolvconf to have static DNS servers set in /etc/resolv.conf. However, when I run sudo resolvconf -u to update /etc/resolv.conf with new static information, I get the error:

resolvconf: Error: /etc/resolv.conf must be a symlink

How can I fix this?

BuZZ-dEE
  • 14,573
Azendale
  • 12,031

4 Answers4

38

It's easy to fix. Just open a terminal and run the following commands:

sudo rm /etc/resolv.conf
sudo ln -s ../run/resolvconf/resolv.conf /etc/resolv.conf
sudo resolvconf -u
Kulfy
  • 18,163
Azendale
  • 12,031
  • 1
    This information is obsolete. /etc/resolv.conf must now be symlinked to ../run/resolvconf/resolv.conf. – jdthood Oct 28 '12 at 19:29
  • The claim that the error message is caused by an interrupted resolvconf run is false. – jdthood Oct 30 '12 at 08:05
  • 1
    Now it's right. :) – jdthood Dec 07 '12 at 08:04
  • 3
    @jdthood : why is ../ needed? Why shouldn't we use sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf? – Basj May 15 '17 at 14:28
  • 2
    @Basj The difference is that it makes the symlink relative: read it as something like "go up a folder, then to 'run', then to 'resolvconf', then to the file 'resolv.conf'". I'm guessing either way works, but why hardcode a path? What if you are working with LXC containers (where the root FS is in a folder)? Then opening the link from the LXC host will take you to the wrong file if you used an absolute path. – Azendale May 16 '17 at 16:33
  • @Azendale Could you please put the above comment in your answer, or do you mind if I edit the answer to include this information? I was about to ask this very question about the relative paths from a similar (separate) answer on another SE site. It's useful info. Cheers! – Cloud Oct 29 '17 at 00:15
  • grep: /etc/resolv.conf: No such file or directory – itsazzad Jun 19 '18 at 06:30
  • In case you wouldn't be able to remove resolve.conf. you should try sudo chattr -a -i /etc/resolv.conf – Phoenix Feb 27 '21 at 19:50
15

As of Ubuntu 12.04 resolvconf is part of the base system. You can recreate the needed symlink by running

dpkg-reconfigure resolvconf

or by doing the following in a terminal.

sudo ln -nsf ../run/resolvconf/resolv.conf /etc/resolv.conf

Note that as of Ubuntu 12.10 resolvconf no longer aborts if /etc/resolv.conf is not a symlink. It does print a warning message, but this can be silenced by putting the line

REPORT_ABSENT_SYMLINK=no

in /etc/default/resolvconf.

jdthood
  • 12,625
  • I'm assuming doing the dpkg-reconfigure command changes /etc/resolv.conf back to being a symlink, even if a normal file is at /etc/resolv.conf? Also, do you have to remove /etc/resolv.conf before doing ln? I get an error trying it on my system, but then again, I wasn't having the error described in this question when I tried it. – Azendale Nov 03 '12 at 16:17
  • Yes, running "dpkg-reconfigure resolvconf" changes /etc/resolv.conf back into a symlink and if there was a file there; it saves a copy of the original file at /etc/resolvconf/resolv.conf.d/original. It's a good idea to remove /etc/resolv.conf before putting a symlink there, but if you use "ln -nsf" it's not necessary to do so. I have just changed the answer to say "ln -nsf" instead of "ln -s". – jdthood Nov 03 '12 at 21:35
2

On my Ubuntu 23:04 installation the /etc/resolv.conf symlink pints too /run/systemd/resolve/stub-resolv.conf

milegrin
  • 421
  • 4
  • 9
  • And here is info on what the stub does https://unix.stackexchange.com/questions/548830/whats-the-difference-between-run-systemd-resolve-stub-resolv-conf-and-run-sys – malhal Dec 12 '24 at 15:44
1

rm -r resolv.conf
nano resolv.conf in it do

nameserver 1.1.1.1

nameserver 1.0.0.1

save it with ctrl+ X.

after that do: sudo apt-get install openresolv

after that: reboot the computer it will work .

Austin Adams
  • 103
  • 4
tarling
  • 11