Resolv.conf gets overwritten at reboot

If you ever encounter the behavior that the /etc/resolv.conf file is overwritten at reboot time, you should follow the next instructions to identify and fix the root cause.

The first thing that you must look is that your interface is not using a DHCP server to get its IP configuration. If such, you must configure DNS servers or the entries you desire in resolv.conf file on the DHCP server directly. If you don’t want your DHCP server to modify your DNS servers, you can modify the network interface configuration file and set the PEERDNS parameter to “no”.

If you are using static addressing then you must ensure that your network interface config file (/etc/sysconfig/network-scripts/ifcfg-ethXX) has the BOOTPROTO parameter set to “none” (some distributions also support “static” option). This parameter also supports the following values:

dhcp – when a DHCP server is used

bootp – when boot protocol is used. Note pump protocol should be used as a replaced for bootp.

Once this parameter has been configured, you must set your static IP configuration as described in a previous article.

Linux distributions have two network managing services, they can be seen in the init.d directory. The old implementation of the networking stack was using the “network” service and bunch of configuration files located in /etc/sysconfig/network-scripts/. This service has been replaced by the newly NetworkManager which is the default one in CentOS 6 and newer versions:

[root@Centos06-1 network-scripts]# ls -al /etc/init.d/ | grep -i network
-rwxr-xr-x. 1 root root 6406 Apr 9 2015 network
-rwxr-xr-x. 1 root root 2205 Jul 24 2015 NetworkManager

If the interface configuration file has the NM_CONTROLLED parameter set to “yes”, then the NetworkManager service will take care of the networking part. Note that this option is set to “yes” by default but, you can change it to “no” if desired.

If your resolv.conf file is gets its content replaced with each reboot then you must set the DNS servers in the interface configuration file, just like in the following example:

Configure DNS servers in Linux

Configure DNS servers in Linux

Remember that you must use the statement “DNS1=X.X.X.X” where x.x.x.x represents the IP address of the DNS server. If you are adding multiple DNS servers then you must append a number to each entry similar to the previous image.

Once you save the configuration file, reboot the server and note that the resolv.conf file is not being overwritten by the NetworkManager service.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s