从 dhclient 的响应中去除特定选项

F30*_*F30 8 ubuntu dhcp debian ntp

我的目标是禁止dhclient使用通过 DHCP 接收的服务器更新我的 NTP 配置,因为它是 Debian/Ubuntu 上的默认设置。但是,我的 DHCP 服务器忽略了请求的选项列表(来自request设置)并且它的答案总是包含一个 NTP 服务器。

所以我想在进一步处理之前删除该选项,或者至少用空值覆盖它。使用该supersede设置可以覆盖,但我没有设法将其设为空。我也找不到完全删除选项的方法。

实际上导致空值的原因是指定了一个无效的 in supersede(例如,包含字母,因为只允许使用数字值)。这实际上是无效的,但会导致日志文件中出现错误。有人知道更好的方法吗?

slm*_*slm -1

我认为您可以dhclient通过`/etc/dhclient.conf 文件进行配置,告诉它您希望它从 DHCP 服务器正式请求值的选项。

\n\n

例子

\n\n
request subnet-mask, broadcast-address, routers, domain-name, \n    domain-name-servers, host-name;\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以通过手册页找到更多相关信息dhclient.conf

\n\n

摘抄

\n\n
There  is a variety of data contained in offers that DHCP servers send to \nDHCP clients.  The data that can be specifically requested is what are\ncalled DHCP Options.  DHCP Options are defined in dhcp-options(5).\n\nThe request statement\n\n [ also ] request [ [ option-space . ] option ] [, ... ];\n\nThe request statement causes the client to request that any server \nresponding to the client  send  the  client  its  values  for  the  \nspecified options.   Only  the  option names should be specified in the \nrequest statement - not option parameters.  By default, the DHCPv4 client \nrequests the subnet-mask, broadcast-address, time-offset, routers, \ndomain-search, domain-name, domain-name-servers, host-name,  nis-domain, \nnis-servers, ntp-servers and interface-mtu options while the DHCPv6 client \nrequests the dhcp6 name-servers and domain-search options.  Note that if you\nenter a \xc2\xb4request\xc2\xb4 statement, you over-ride these defaults and these options \nwill not be requested.\n\nIn some cases, it may be desirable to send no parameter request list at all.  \nTo do this, simply write the  request  statement  but  specify  no \nparameters:\n\n    request;\n\nIn most cases, it is desirable to simply add one option to the request list \nwhich is of interest to the client in question.  In this case, it is best to \n\xc2\xb4also request\xc2\xb4 the additional options:\n\n    also request domain-search, dhcp6.sip-servers-addresses;\n
Run Code Online (Sandbox Code Playgroud)\n\n

通过 /dhclient-exit-hooks.d 禁用?

\n\n

浏览 Ubuntu 12.10 安装后,我注意到这个目录,/etc/dhcp/dhclient-exit-hooks.d里面有这个文件,ntpdate. 查看此文件,它包含一个 shell 脚本,当通过 DHCP 获取或释放租约时,该脚本将在系统上执行更新。您可以通过此脚本禁用 NTP 服务器的更新,只需注释掉此文件即可:

\n\n
ntp_servers_setup() {\n    case $reason in\n        BOUND|RENEW|REBIND|REBOOT)\n            ntp_servers_setup_add\n            ;;\n        EXPIRE|FAIL|RELEASE|STOP)\n            ntp_servers_setup_remove\n            ;;\n    esac\n}\n\n\nntp_servers_setup\n
Run Code Online (Sandbox Code Playgroud)\n