/etc/resolv.conf is being overwritten everytime??? | Ubuntu work around

Yes it is true in ubuntu, even if we manually set custom nameservers in /etc/resolv.conf it will overwrite on next reboot or network restart or modem/router restart. It is really annoying once we set google nameservers or opendns or whatever in resolv.conf it goes back to default page on each instance of restart or modem reconnect. The operation of setting attribute to /etc/resolv.conf is not supported here.

===========
root@vaiocyber:~# chattr +i /etc/resolv.conf
chattr: Operation not supported while reading flags on /etc/resolv.conf
===========

The work around to get it permanently fixed is as follows:

Initially my resolv.conf looked like.

===========
root@vaiocyber:~# 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
search Home
===========

Open file /etc/network/interfaces and add the line “dns-nameservers NS1-IP NS2-IP” to the bottom, like I wanted to add opendns IPs in my system. For that I did add “dns-nameservers 208.67.222.222 208.67.220.220” to the interfaces file. Now the file looks like in my ubuntu is.

===========
root@vaiocyber:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
dns-nameservers 208.67.222.222 208.67.220.220
===========

Now restart network by “service networking restart” or “ifdown eth0 ; ifup eth0” or Reboot modem or Reboot the ubuntu machine itself. From now onwards the custom nameservers we set will still there be in place until we revert the changes made 😀

After restart, the resolv.conf file will automatically added with custom nameservers we set in interfaces file 🙂

see…

===========
root@vaiocyber:~# 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 208.67.222.222
nameserver 208.67.220.220
nameserver 127.0.1.1
search Home
===========

Enjoy fast surfing now 🙂

 

(For more detailed information… read “man resolvconf“)

Leave a Reply

Your email address will not be published. Required fields are marked *