dhclient 没有设置默认网关

dhclient 没有设置默认网关

我在 Azure 云中运行几个 Ubuntu 16.04 VM。每当我重新启动 VM 时,我都必须手动设置默认网关。

网关应该由 dhclient 设置。我激活了调试并得到了以下信息:

root@backend01:/etc/dhcp/dhclient-exit-hooks.d# cat /tmp/dhclient-script.debug

root@backend01:/etc/dhcp/dhclient-exit-hooks.d# cat /tmp/dhclient-script.debug
Thu Jun  2 17:18:33 UTC 2016: entering /etc/dhcp/dhclient-enter-hooks.d, dumping variables.
reason='PREINIT'
interface='eth0'
--------------------------
Thu Jun  2 17:18:33 UTC 2016: entering /etc/dhcp/dhclient-enter-hooks.d, dumping variables.
reason='REBOOT'
interface='eth0'
new_ip_address='10.10.0.13'
new_network_number='10.10.0.0'
new_subnet_mask='255.255.0.0'
new_broadcast_address='10.10.255.255'
new_routers='10.10.0.1'
new_rfc3442_classless_static_routes='0 10 10 0 1 32 168 63 129 16 10 10 0 1'
new_domain_name='azure-prod'
new_domain_search='azure-prod.'
new_domain_name_servers='10.11.0.250 10.11.0.251'

因此路由器选项设置正确。甚至租约文件也显示正确的值:

lease {
  interface "eth0";
  fixed-address 10.10.0.13;
  server-name "RD7CFE90879C98";
  option subnet-mask 255.255.0.0;
  option dhcp-lease-time 4294967295;
  option routers 10.10.0.1;
  option dhcp-message-type 5;
  option dhcp-server-identifier 168.63.129.16;
  option domain-name-servers 10.11.0.250,10.11.0.251;
  option domain-search "azure-prod.";
  option dhcp-renewal-time 4294967295;
  option rfc3442-classless-static-routes 0,10,10,0,1,32,168,63,129,16,10,10,0,1;
  option unknown-245 a8:3f:81:10;
  option dhcp-rebinding-time 4294967295;
  option domain-name "azure-prod";
  renew 0 2152/07/09 23:41:47;
  rebind 0 2152/07/09 23:41:47;
  expire 0 2152/07/09 23:41:47;
}

我的 /etc/dhcp/dhclient.conf 如下所示:

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
    domain-name, domain-name-servers, domain-search, host-name,
    dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
    netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers;


timeout 300;

supersede domain-name "azure-prod";
supersede domain-search "azure-prod";

为什么 dhclient 没有设置我的默认路由?

答案1

我找到了问题。由于 Azure DHCP 设置了rfc3442-classless-static-routes选项,路由器选项被 dhclient 脚本忽略。

rfc3442 由退出钩子脚本处理/etc/dhcp/dhclient-exit-hooks.d/rfc3442-classless-routes

我的问题是我有另一个自定义的退出钩子,它exit 0在最后执行了一个操作,因此结束了 dhclient 脚本的执行,而该脚本又从未执行过 rfc3442-classless-routes 退出钩子。

这个问题埋得很深,几乎浪费了我一天的时间。所以我希望这能防止以后有人遇到同样的问题。

相关内容