PDA

View Full Version : Ubuntu overwriting /etc/resolv.conf search / nameservers, how to fix?



Fli
06-29-2017, 09:56 AM
Hello,

in Ubuntu 15.04 i found that my provider is using their IP as a nameserver and their domain as a search inside /etc/resolv.conf

i tried to change and delete "search" line and update nameservers, but changes are lost after restart or after i update resolv.conf by command "resolvconf -u".

I tried to write protect the file by command: "chattr +i /etc/resolv.conf" and it says: "chattr: Operation not supported while reading flags on /etc/resolv.conf"

i see /etc/resolv.conf is a symlink, so i tried chattr also on the destination file (/run/resolvconf/resolv.conf), same result.

In /etc/network/interfaces one can update these lines:

dns-nameservers 8.8.8.8 8.8.4.4
dns-search google.com

restart networking? (not sure if needed): service networking restart


but when i run "resolvconf -u" it still ends with wrong "search" line mentioning my server provider domain which i do not want.

so i moved symbolic link and created new file: "mv /etc/resolv.conf /etc/resolv2.conf;echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf"

when i modify first nameserver IP in /etc/resolv.conf to lets say non existing 1.1.1.1 , then i run "resolvconf -u", it says: "/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf", which is OK, as i have removed symlink and created new file instead of it.

Now i test which nameserver is used:

dig something.unknown | grep SERVER:

;; SERVER: 8.8.4.4#53(8.8.4.4)

So this way it seems like the /etc/resolv.conf is used and will no longer be overwritten by the system and will not be updated/rewritten by the system. It is maybe not smart way, but i do not know how to modify "search" line in /etc/resolv.conf so the system will nto reset my change to this line.

------------
So in short what i did to prevent overwriting /etc/resolv.conf is to execute command:
mv /etc/resolv.conf /etc/resolv2.conf;echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf