0

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
4

2 回答 2

3

也许为时已晚,您已经通过其他方式解决了问题;但无论如何,由于我受到同样问题的影响,我想我会插话。

您的问题是 NetworkManager。这就是执行 dhclient,使用不同的配置文件而不执行任何钩子。这在 Ubuntu 中被归档为一个错误:

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

您可以将脚本放在 /etc/NetworkManager/dispatcher.d 中,以便在 NetworkManager 调出界面时执行。在上面的错误中有一个导出到这些脚本的变量列表。如果您不需要它们中的任何一个,而只想在界面启动时执行某些操作,那么您应该已经足够了。

希望能帮助到你。

于 2012-11-16T09:24:50.717 回答
0

直到几分钟前我也遇到了同样的问题,并选择了 dispatcher.d 脚本路径。因此,我编写了以下脚本并将其放入 /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

这个想法是,无论发生什么,都将所有 DNS 请求发送到 dnsmasq 正在等待回答的 localhost。现在所需要的只是 tel dnsmasq 在哪里可以找到真正的 resolv.conf 文件,因此它会知道将 DNS 请求发送到它不知道的主机名的位置。在 /etc/dnsmasq.d 中创建一个文件,比如 /etc/dnsmasq.d/upstream.conf 并将其放入这一行

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

/var/run/NetworkManager/resolv.conf是网络管理器存储它通过 DHCP 接收的 DNS 信息的地方。现在,每次您从 DHCP 服务器获得一些 DNS 信息时,您的 dnsmasq 服务器都会知道它们并相应地转发请求。

而且,你已经完成了。您唯一担心的是 dnsmasq 是否让您失望。

于 2014-12-09T21:04:21.247 回答