I'm seeking to prepend a local resolver into /etc/resolv.conf using a dhclient script at /etc/dhcp/dhclient.conf:

prepend domain-name-servers;

Is there a way for me to force dhclient to run this script, prepending my resolver into /etc/resolv.conf? When using NetworkManager, restarting that service will cause the script to run, but I am in a Docker container and I don't have NetworkManager.

What can I execute to run this script?


On systems I use, there are two systems of scripts that run each time the DHCP client renews its lease. These are located in /etc/dhcp/dhclient-enter-hooks.d/... and in /etc/dhcp/dhclient-exit-hooks.d/... They might be elsewhere, depending on your Linux variant. You can add scripts there to execute each time the lease is renewed, and those scripts will have access to all of the key/value pairs sent by the DHCP server, as shell variables. What you do with them in your hook script(s) is wide open. I assume you're using DHCP tools that are ISC DHCP compatible. If not, maybe you can consider switching to that. They document how the client hook scripts can get at the parameters sent from the DHCP server, and give some useful examples.

  • But is there a way for me to manually trigger those scripts? – Naftuli Kay Apr 17 at 16:53
  • You could try running 'dhclient'. Look for the appropriate option(s) that would invoke the script(s) as you require. The dhclient binary normally becomes a daemon, but it has other ways to run it. There's nothing to stop you from invoking it from a shell or shell script. – Rod Nussbaumer Apr 17 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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