CentOS 6 – nameserver entry in resolve.conf resetting after restarting network services?

In /etc/resolv.conf, I’ve changed the nameserver line to a new IP address. After saving and exiting, I run service network restart. I then go open /etc/resolve.conf again and see that the IP address I changed is now back to what it was prior to changing.

Why is this happening?

Asked By: Lester Peabody


Might be you have dhcp-client in your system and it make resetting your resolv.conf file after restarting the network service.

Check in /etc/sysconfig/network or interface file whether dhcp-client protocol has defined and try to configure the static ip.

If not, you can protect your /etc/resolv.conf from being modified by anything is setting the write-protection attribute.

chattr +i /etc/resolv.conf
Answered By: Mughil

If you are using DHCP for address assignment, the cleanest way to accomplish modifying resolv.conf is to make the changes on the DHCP server side. That will in turn correctly update resolv.conf

Answered By: midnightsteel

According to the RedHat 6 Documentation this is the same as with RedHat5:

Put PEERDNS=no either into the global configuration file, or into the specific interface-configuration file.

Answered By: Nils

If you are running on Centos/RHEL edit the ifcfg configuration file and add


Then restart networking using service network restart

I know this is a very old question, I am adding my answer to help those who didn’t accept the accepted answer above. Such as myself.

Answered By: Michael Heathman