Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 4 down vote accepted

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.

share|improve this answer
    
Thanks, this is exactly what I was looking for. –  Lester Peabody Nov 16 '12 at 22:44

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
share|improve this answer

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

share|improve this answer

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

DNS1="xxx.xxx.xxx.xxx"
DNS2="xxx.xxx.xxx.xxx"

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.