Saturday, November 30, 2013

How to avoid NetworkManager overwriting resolv.conf in Centos 6 (RHEL 6, Fedora)

This one took me a while to figure out mainly due to conflicting information on the web.

The easiest way to avoid NetworkManager to overwrite your /etc/resolv.conf when getting a dhcp lease is to create a new file /etc/dhcp/dhclient-eth0.conf. For some reason in Centos 6 Network manager will not pick up the /etc/dhcp/dhclient.conf or /etc/dhclient.conf files. Also sometimes it is good to delete the /var/run/nm-dhclient-eth0.conf file since sometimes this file will not be recreated.

Here is my /etc/dhcp/dhclient-eth0.conf file. Change eth0 to the name of your interface if different.

# /etc/dhcp/dhclient-eth0.conf
# Use Google DNS instead of DCHP provided
supersede domain-name-servers 8.8.8.8;
# Correctly set the local domain name
supersede domain-search "mydomain.com";
supersede domain-name "mydomain.com";

The supersede directive will replace the DHCP configuration with your own. If you wish to append or prepend, use the 'append' or 'prepend' directive.

Now regenerate the /etc/resolv.conf file

sudo service NetworkManager restart

No comments:

Post a Comment