I am facing a strange situation on all my RHEL 7 servers. All the RHEL 7 VMs are provisioned using a provisioning tool which connects to a VM offering a DHCP IP, once provisioning is complete we run a batch script to make the NICs static and update resolv.conf with valid values.

But we can see that /usr/sbin/dhcpclient-script is updating the resolv.conf with its values.

Both NIC's config file has BOOTPROTO=static, DNS1=x.x.x.x, DNS2=x.x.x.x, PEERDNS=no and other required values.

I am not able to understand why resolv.conf is modified by the DHCP server used for provisioning even after setting the NIC to static.

  • May be related to systemd - see unix.stackexchange.com/questions/389774/…
    – Patrick
    Oct 31, 2017 at 10:28
  • Might also be related to NetworkManager. Oct 31, 2017 at 10:39
  • the netwokManager is not installed on the server, what i can see is that whiile provisioning the server the NIC is named as ksdev0 and at a later point after provisioning we run the script to rename ksdev0 to eth-xxxx, but even now i can see in var/log/messages DHCPREQUEST to ksdev0, so i guess the kernel still refers to ksdev0 even though the NIC does not exist, and a reboot is not performed after ksdev0 is renamed to eth-xxx. Oct 31, 2017 at 10:43
  • Does a reboot solve the problem?
    – fpmurphy
    Oct 31, 2017 at 12:21
  • Can you post the script? Maybe it's renewing the dhcp lease and so updating the resolv.conf...
    – Zip
    Oct 31, 2017 at 12:29

3 Answers 3


Create a /etc/dhcp/dhclient-enter-hooks file with the following content:


Make it executable chmod +x /etc/dhcp/dhclient-enter-hooks

The explanation on the man dhclient-script


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.

How To: Make Sure /etc/resolv.conf Never Get Updated By DHCP Client

  • I've posted a slightly adapted answer if you have a /etc/dhcp/dhclient-enter-hooks.d directory, like I see on Debian Buster. Mar 7, 2021 at 17:24

All credit to @GAD3R for this answer. The directory structure on my system encouraged me to put the file in a .d directory. That seems like the more maintainable way of the future. I'd edit it into the answer from @GAD3R but I don't know if that would be welcome and perhaps systems that don't have the .d directory are still around. I like to have solutions I can just copy-and-paste:

sudo tee /etc/dhcp/dhclient-enter-hooks.d/unhand-resolv-conf <<EOF
sudo chmod +x /etc/dhcp/dhclient-enter-hooks.d/unhand-resolv-conf

Likely you're hitting how resolvconf works by default.

If you'd like nothing to change your /etc/resolv.conf at all, ever, then arrange to run the following command. Be sure to arrange for this to run at reboot time too...

resolvconf --disable-updates

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .