rouserajesh
rouserajesh

Reputation: 7

Ubuntu 11.10 dhclient-enter-hook.d scripts not invoked

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

Upvotes: -1

Views: 2309

Answers (2)

gmelis
gmelis

Reputation: 101

I had the same problem up to a few minutes ago, and chose to go along the dispatcher.d script path. So, I wrote the following script and put it in /etc/NetworkManager/dispatcher.d/99resolv.conf.dhclient

#!/bin/sh -e
# Script to dispatch NetworkManager events
# It overwrites /etc/resolv.conf with the DNS of preference
# See NetworkManager(8) for further documentation of the dispatcher events.

sleep 3
rm -f /etc/resolv.conf && echo nameserver 127.0.0.1 > /etc/resolv.conf
service dnsmasq reload

The idea is, whatever happens, send all DNS requests to localhost, where dnsmasq is waiting to answer. All that's needed now is tel dnsmasq where to find the real resolv.conf file, so it'll know where to send DNS requests for host names it does not know. Create a file in /etc/dnsmasq.d, say /etc/dnsmasq.d/upstream.conf and put in it this line

resolv-file=/var/run/NetworkManager/resolv.conf

/var/run/NetworkManager/resolv.conf is where Network Manager stores DNS info it receives via DHCP. Now every time you get some DNS info from a DHCP server, your dnsmasq server will know about them and forward requests accordingly.

And, you're finished. Your only worry will be if dnsmasq ever fails you.

Upvotes: 0

rsuarez
rsuarez

Reputation: 179

maybe it's too late and you've solved the problem through other means; but anyway, as I'm affected by the same issue, I thought I'd chime in.

Your problem is NetworkManager. That's what's executing dhclient, using a different configuration file and not executing any hooks. This is filed as a bug in Ubuntu:

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/293139

You can put scripts in /etc/NetworkManager/dispatcher.d to be executed when NetworkManager brings up an interface. In the bug above there is a list of variables exported to these scripts. If you don't need any of them, and just want to execute something on interface start, you should have enough with this.

Hope it helps.

Upvotes: 3

Related Questions