0

I am using Red Hat 6.7

when I update my resolv.conf file as the following:

 options attempts:2 options timeout:1 search usa.Pe.corp tedcruz.usa.fb.corp nameserver 10.9.145.145 nameserver 10.9.100.103 nameserver 43.11.0.14 

after service network restart I get a different resolv.conf file as the following

 options attempts:2 options timeout:1 search usa.Pe.corp nameserver 10.9.145.145 

How to disable/block the resolv.conf file from any changing?

Why the file is changing after network restart or after reboot?

2
  • 2
    Is this perhaps a /etc/resolv.conf file that has "DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN" at the top? Commented Apr 16, 2016 at 20:59
  • I update the /etc/resolve.conf on the first time after I installed the linux machine , so this is the first update ! Commented Apr 16, 2016 at 21:03

1 Answer 1

2

The dhclient-script is doing this. It checks to see what nameservers and domains are visible. Sometimes that is useful.

According to its manual page,

When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script.

On after defining the make_resolv_conf function, the client script checks for the presence of an executable /etc/dhcp/dhclient-enter-hooks script, and if present, it invokes the script inline, using the Bourne shell '.' command. The entire environment documented under OPERATION is available to this script, which may modify the environment if needed to change the behaviour of the script. If an error occurs during the execution of the script, it can set the exit_status variable to a nonzero value, and /sbin/dhclient-script will exit with that error code immediately after the client script exits.

For example, as shown in How To: Make Sure /etc/resolv.conf Never Get Updated By DHCP Client, you can create or append to /etc/dhcp/dhclient-enter-hooks this dummy function:

make_resolv_conf(){ : } 
4
  • Thomas thx for your solution so create anew file with this content will protect on the resolve.conf from changing, but let me suggest other option as chattr +i resolve.conf , what you think about this ? Commented Apr 16, 2016 at 20:57
  • You can certainly try that, or the dummy function. I've seen comments about both, where they work for some people and not for others. Commented Apr 16, 2016 at 21:05
  • so from your opinion what is the best choice? Commented Apr 16, 2016 at 21:06
  • The function is more easily tested: if it works, you can put an "echo" statement in the function to see it working. The chattr approach is less easily verified. So I suggested the function. Commented Apr 16, 2016 at 21:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.