Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a box with Ubuntu 11.10 installed. And the box was configured to get IP and hostname from dhcp.

We have set to scripts in /etc/dhcp/dhclient-enter-hooks.d/ folder. But these scripts were not invoked/executed. I have similar scripts in another box, which has Ubuntu 10.04 installed and hook scripts executes without issues. One difference is that in the 11.10 box has NetworkManager installed.

# ps -ef | grep dhclient
root       746   695  0 03:52 ?        00:00:00 /sbin/dhclient -d -4 -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /var/run/ -lf /var/lib/dhcp/ -cf /var/run/nm-dhclient-eth0.conf eth0

How did I test that the script in /etc/dhcp/dhclient-enter-hooks.d was not running? I have placed a simple script "mytest" which has below code in /etc/dhcp/dhclient-enter-hooks.d. The file /tmp/enter-hook.out was never generated.

echo "this is test file to test dhclient-enter-hook" > /tmp/enter-hook.out

Snip of my /etc/network/interfaces

# cat /etc/network/interfaces 
auto lo
iface lo inet loopback

auto eth0 inet dhcp
share|improve this question

Since this question isn't really a question, I'll assume that the question is "how can I get the dhclient-{enter,exit}-hooks to run?" The short answer is you can't without some work. See this bug for a good discussion on the issue and some solutions.

As suggested by the OP, network manager (NM) is the problem. Here's an example of a dhclient invocation by NM:

/sbin/dhclient -d -4 -sf /usr/lib/NetworkManager/nm-dhcp-client.action \
    -pf /var/run/ -lf <lease file> \
    -cf /var/run/nm-dhclient-wlan1.conf wlan1

Notice the "-sf /usr/lib/NetworkManager/nm-dhcp-client.action". This is a special program provided by NM, which overrides the default script for dhclient, which is at /sbin/dhclient-script. The default script behaves as you would expect and is documented in "man dhclient-script".

nm-dhcp-client.action is a C program, so you'll need the source to figure out what its doing. But looking in the source you'll notice that it doesn't run any of the enter/exit scripts directly by default.

Probably the best (least hacky) solution is to write a /etc/NetworkManager/dispatcher.d script that runs the enter/exit scripts when the interface comes up and if the DHCP* environment variables exist (see man NetworkManager). Since you can only pass variables that NM gives the dispatcher script, this might not be a fully transparent solution.

An untested, hacky, but easier alternative would be to rename /usr/lib/NetworkManager/nm-dhcp-client.action and put a script in its place that unconditionally exec's into the newly named nm-dhcp-client.action. You could pretty much copy a large part of /sbin/dhclient-script that runs the enter/exits hooks, so it should be pretty simple to create the script. This should work with pre-existing hook scripts, whereas the former solution may not (due to unavailability of expected variables).

NM really should already be running the hooks because it seems like some packages don't function as expected without it.

share|improve this answer
Instead of the renaming nm-dhcp-client.action hack‌​ks/ shows a better way, namely specify a script in the dhclient.conf (which does override the command line arg). The override script must be at /etc/dhcp/dhclient-script or you'll need to change apparmor. – crass Aug 8 '12 at 10:52

just came across a what seems like unrelated resolution to the problem - having the interface not properly declared in /etc/network/interfaces made the difference. none of the hook-scripts got called and I was about to proceed with the workaround involving the NetworkManager: Be sure to have something like this in /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# these two lines are here by default
auto lo
iface lo inet loopback

# this was missing in my case and while the address was retrieved via DHCP, additional 
# options like ntp-servers were never retrieved:
auto eth0
iface eth0 inet dhcp
share|improve this answer

Your Answer


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.