这是我的/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; }
当我运行“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.
我使用strace确保dhclient确实正在读取conf文件.为什么不注意我的“固定地址192.168.1.222”线?为什么它会为192.168.1.27执行DHCPREQUEST?
解决方法
正如Zoredache正确指出的那样:固定地址设置仅适用于仅在DHCP服务器不响应时才有效的租约定义.请参见“租赁声明”部分中的
http://linux.die.net/man/5/dhclient.conf.
你想要的是什么
interface "eth0" { send dhcp-requested-address 192.168.1.222; }
这在dhcp-options:@L_502_1@的联机帮助页中有记录,并且符合http://www.rfc-editor.org/rfc/rfc2132.txt中提供的DHCP选项RFC
请注意:我最近遇到dhclient3没有获得具有此配置的IP,因为已经请求了所请求的地址.服务器回复DHCPNAK请求,客户端将在一段时间后放弃.我原本以为如果请求的地址不可用,DHCP客户端最终会以另一个地址结束.
我使用这种方法试图确保我总是知道我的服务器的地址而不诉诸dyndns.com之类的东西而最终没有连接.