Stop your DNS Servers from changing after every reboot while using DHCP

| | 1 min read

Do you find your custom DNS server entries being deleted after every reboot or after every disconnection? Do you use DHCP but still want to use your own DNS servers? Do you want to use OpenDNS and ignore the DNS servers provided by your ISP? Well here is how you can do this on Ubuntu. This solution applies to Ubuntu but might very well work for other distributions of GNU Linux as well.

Open terminal and run

gksu gedit /etc/dhcp3/dhclient.conf

This will open up gedit with super user privileges and open /etc/dhcp3/dhclient.conf for editing. Inside this file add the following lines to add the openDNS nameservers.

prepend domain-name-servers 208.67.222.222;
prepend domain-name-servers 208.67.220.220;

Instead of the OpenDNS servers you can set your own preferred DNS servers. The prepend lines above prepends the given DNS servers to the /etc/resolv.conf file as it is being rewritten by dhclient at the time of a new DHCP request either when the server restarts or when the connection is restarted or when the DHCP lease expires.