Question

I'm using Ubuntu 11.10 and I manually configure DNS servers in /etc/resolv.conf but it gets somehow overwritten after I reboot. How can I prevent this?

Thanks.

Was it helpful?

Solution 3

I figure that the NetworkManager is overwriting the /etc/resolv.conf file. In my case it was the order in which my DNS servers were listed was something I wanted to change. You can do that through the NetworkManager by editing your connection IP4V settings.

OTHER TIPS

As you can read in the header of resolv.conf :

Dynamic resolv.conf file for glibc resolver generated by resolvconf

So, the resolv.conf is generated, if you want to keep the resolvconf configuration after reboot, you will have to edit /etc/resolvconf/resolv.conf.d/base. In that file, put in your info as you would in resolv.conf.

nameserver 8.8.8.8

Then regenerate resolv.conf with resolvconf:

sudo resolvconf -u

After reading other answers, I still needed something different for the following reasons:

  • I'm not using resolvconf, just plain /etc/resolv.conf.
  • Using chattr +i to lock down resolv.conf seems too hacky. I need Puppet to be free to make changes 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.

You have DHCP client doing this. Follow these instructions to override that.

I use the following line : chattr +i /etc/resolv.conf

to undo use : chattr -i /etc/resolv.conf

Let me know if it worked...

NetworkManager can be configured to use manually entered IPv4 configuration, or get from DHCP IP/netmask/router only - in such a case it should not change /etc/resolv.conf

However, one may want have his own settings in the /etc/resolv.conf - like nameserver or domain to search; I just need a domain and I did by adding a file /etc/NetworkManager/dispatcher.d/99my_fix containing:

#!/bin/bash rc=/etc/resolv.conf; le="search my.domain" grep -q domain $rc && ! grep -q "$le" $rc && echo "$le" >> $rc

Of course I chmod-ed +x it. The NetworkManager invokes it after setting the /etc/resolv.conf and my script fixes it if nesessary; the first grep detects that network is up, the second that the fix was not applied - they both are necessary for the fix to be applied.

I had the same problem and I edited my `/etc/dhcp/dhclient.conf' file by adding domain-name and domain-name-servers

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

192.168.56.103 is my vm running bind9 and my domain name is local.com

and I have removed the same from request section as well.

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 "mydomain.com";
supersede domain-search "mydomain.com"
supersede domain-name-servers 8.8.8.8;

In this particular case the name server is located at "8.8.8.8" and the domain name is "mydomain.com". Substitute your particular information.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top