What overwrites /etc/resolv.conf on every boot?

  1. You shouldn't manually update your resolv.conf, because all changes will be overwritten by data that your local DHCP server provides. If you want it to be static, run sudo dpkg-reconfigure resolvconf and answer "no" to dynamic updates. If you want to add new entries there, edit /etc/resolvconf/resolv.conf.d/base and run sudo resolvconf -u, it will append your entries and DHCP server's entries.

  2. Try to edit your /etc/network/interfaces and add your entries there, like

     auto eth0 
     iface eth0 inet dhcp 
     dns-search google.com 
     dns-nameservers dnsserverip 
    

and then restart /etc/init.d/networking restart or sudo ifdown -a and sudo ifup -a

  1. Your system uses udhcp which is a very small DHCP client program. The udhcp client negotiates a lease with the DHCP server and notifies a set of scripts when a leases is obtained or lost. You can read about it's usage here or just edit this script (as you did).

Ubuntu 16.04 If the network interfaces for your server instance is controlled by DHCP, the dhclient program will overwrite your /etc/resolv.conf file whenever the networking service is restarted.

You can fix the issue by editing the /etc/dhcp/dhclient.conf file and adding “supersede” statements for domain-name, domain-search and domain-name-servers as follows:

supersede domain-name "local.com";
supersede domain-search "local.com";
supersede domain-name-servers 192.168.56.103;

In this particular case the name server is located at "192.168.56.103" and the domain name is "local.com"

Note that each line is terminated by a semi-colon and the domain name is enclosed in double quotes.


I ran into this too. Commenting out domain-name-server didn't fix it for me either.

Also, I'm not using resolvconf, just plain /etc/resolv.conf.

I didn't try using chattr +i to lock down resolv.conf because it seems too hacky. Also, I want Puppet to be able to modify resolv.conf when necessary.

The best solution I found overrides the default behavior of dhclient using its documented hooks.

Create a new file at /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate with the following contents:

#!/bin/sh
make_resolv_conf() {
    :
}

Then make the file executable:

chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate

Now when dhclient runs -- either on reboot or when you manually run sudo ifdown -a ; sudo ifup -a -- it loads this script nodnsupdate. This script overrides an internal function called make_resolv_conf() that would normally overwrite resolv.conf and instead does nothing.

This worked for me on Ubuntu 12.04.