Auto generate /etc/resolv.conf
Solution 1
You are placing the changes you want into the wrong directory. NetManager allows custom configuration of the file by editing the base, head and tail by placing your preferences in this directory:
/etc/resolvconf/resolv.conf.d/head
/etc/resolvconf/resolv.conf.d/base
/etc/resolvconf/resolv.conf.d/tail
You can correct this by moving your /etc/resolvconf/base
to /etc/resolvconf/resolv.conf.d/base
.
The content you're seeing after reboot is the content of the /etc/resolvconf/resolv.conf.d/head
file. It takes precedence over all and as you can see, is preserved.
The priority choices should be placed there.
Solution 2
You can add the nameservers in the resolv.conf
and make it immutable, which means - it can not be modified.
echo 'nameserver 8.8.8.8' > /etc/resolv.conf
sudo chmod 444 /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
That should do a trick. To modify the file again do: sudo chattr -i /etc/resolv.conf
Related videos on Youtube
Jiří Liška
Updated on September 18, 2022Comments
-
Jiří Liška over 1 year
I have manually edited
/etc/resolvconf/base
to addopenDNS
name servers, and then runsudo resolvconf -u
to update the/etc/resolv.conf
file.However changes are discarded on each reboot.
How do I preserve those changes?
$ cat /etc/os-release NAME="Ubuntu" VERSION="16.04.3 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.3 LTS" VERSION_ID="16.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" VERSION_CODENAME=xenial UBUNTU_CODENAME=xenial
edit:
/home/pkaramol $ cat /etc/resolvconf/resolv.conf.d/base nameserver 208.67.222.222 nameserver 208.67.220.220 /home/pkaramol $ sudo resolvconf -u /home/pkaramol $ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 127.0.1.1
-
Robert Riedl over 6 yearsDo you use the GUI and have Network Manager running ? That will override/overwrite what you are doing in
resolv.conf
-
-
Jiří Liška over 6 yearsHi thx but pls check my edit
-
Apologician over 6 yearsI have never used the
base
or thetail
. I always use thehead
so that my entry would take precedence. Will you test the/etc/resolvconf/resolv.conf.d/head
option and post the results? I had mentionedbase
because of the content of your question, which may loose to something else taking place. The text in your email (DO NOT EDIT
) is part of the/etc/resolvconf/resolv.conf.d/head
file which appears to be preserved. I'll edit my answer based on the new content in your question. -
Jiří Liška over 6 yearsyep...
head
seems to work even after the reboot..thx -
Apologician over 6 yearsThanks! Please consider accepting the answer by clicking the Grey checkmark. It'll help others to easily find solutions that work.
-
Jiří Liška over 6 yearsjust accepted your answer
-
Syam kumar KK almost 5 yearsIts worked for me, thank you so much...