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 127.0.0.1;
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
.
我可以执行什么来运行此脚本?
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.