为什么 dhclient 不使用我告诉它请求的静态 IP?

mik*_*ike 5 dhcp linux

这是我的 /etc/dhcp3/dhclient.conf:

request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        netbios-name-servers, netbios-scope, interface-mtu;
timeout 60;
alias {
  interface "eth0";
  fixed-address 192.168.1.222;
}
lease {
  interface "eth0";
  fixed-address 192.168.1.222;
  option subnet-mask 255.255.255.0;
  option broadcast-address 255.255.255.255;
  option routers 192.168.1.254;
  option domain-name-servers 192.168.1.254;
}
Run Code Online (Sandbox Code Playgroud)

当我运行“dhclient eth0”时,我得到了这个:

There is already a pid file /var/run/dhclient.pid with pid 6511
killed old client process, removed PID file
Internet Systems Consortium DHCP Client V3.1.1
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

wmaster0: unknown hardware address type 801
wmaster0: unknown hardware address type 801
Listening on LPF/eth0/00:1c:25:97:82:20
Sending on   LPF/eth0/00:1c:25:97:82:20
Sending on   Socket/fallback
DHCPREQUEST of 192.168.1.27 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.1.27 from 192.168.1.254
bound to 192.168.1.27 -- renewal in 1468 seconds.
Run Code Online (Sandbox Code Playgroud)

我使用 strace 来确保 dhclient 确实正在读取该 conf 文件。为什么它不注意我的“固定地址 192.168.1.222”行?为什么它会为 192.168.1.27 执行 DHCPREQUEST?

Blu*_*orn 10

正如 Zoredache 正确指出的那样:固定地址设置仅适用于仅当 DHCP 服务器不响应时才有效的租用定义。请参阅“租赁声明”部分下的http://linux.die.net/man/5/dhclient.conf

你想要的是

interface "eth0" {
    send dhcp-requested-address 192.168.1.222;
}
Run Code Online (Sandbox Code Playgroud)

这记录在 dhcp-options 的联机帮助页中:http : //linux.die.net/man/5/dhcp-options并符合http://www.rfc-editor.org/rfc上的 DHCP 选项 RFC /rfc2132.txt

不过请注意:我最近遇到 dhclient3 没有使用此配置获取 IP,因为请求的地址已被占用。服务端回复DHCPNAK请求,过一会客户端放弃。我原以为如果请求的地址不可用,DHCP 客户端最终会得到另一个地址。

我使用这种方法是为了确保我始终知道我的服务器的地址,而无需求助于 dyndns.com 之类的东西,但最终却没有连接。


Zor*_*che 6

拒绝用于拒绝来自具有特定地址的服务器的报价。不能拒绝服务器提供的地址。

拒绝语句使 DHCP 客户端拒绝来自服务器标识符与任何指定主机或子网匹配的服务器的提议。这可以用来避免被流氓或错误配置吗?配置dhcp服务器,

仅当 DHCP 服务器不响应时才使用定义的租约。

租赁{租赁声明[...租赁声明]}

DHCP 客户端可能会在一段时间后决定(请参阅 PROTOCOL TIMING)它不会成功联系服务器。

如果您想要一个特定的地址,您可能应该在服务器上设置一个预订。