Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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/dhclient-eth0.pid -lf /var/lib/dhcp/dhclient-559273da-a027-458e-b124-bdbb4976ee17-eth0.lease -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.

#!/bin/sh
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

3 Answers 3

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/dhclient-wlan1.pid -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 http://andytson.com/blog/2009/03/workaround-so-networkmanager-runs-dhclient-hoo‌​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

sorry about the bad formatting above.... now using chrome:

To make it work, 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
    
You could have just hit "edit" and made the necessary corrections. You didn't have to create a new id and leave an otherwise identical answer. Clean-up (delete) your other post. Also you should take the site tour to get a general idea on how this site is organized. –  hmayag May 4 at 21:49

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

 
discard

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.