Sunday, June 7, 2015

How to persist resolv.conf modifications

Default resolv.conf in my Ubuntu box is as follows,
udara@udara-home:~$ 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
Assume a scenario where I need to use a different DNS.. Eg: -google dns- 8.8.8.8

I can achieve this by modifying above resolv.conf, but that change won't persists after Ubuntu box restart, networking restart or my router restart.

How to persist my change,

Open /etc/network/interfaces using your favorite text editor, in my case it's vi :)
sudo vi /etc/network/interfaces
Update /etc/network/interfaces according to your preference. You can append dns-nameservers 8.8.8.8 to the end.


Eg:-
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
dns-nameservers 8.8.8.8

Note:- I tried different alternatives like update resolv.conf using a bash script during server restart, adding immutable characteristic to resolv.conf using chattr tool. But above is the only viable solution I can recommend to someone.

No comments:

Post a Comment