send dhcp-requested-address 10.23.33.254;
当我的dhclient.conf文件中存在此选项时,我的客户端正是我想要的:始终从我的专用网络上的DHCP服务器获取所请求地址的租约,其中DHCP范围是10.23.33.0/24.但是,如果我将计算机连接到请求的地址不在服务器的DHCP地址范围内的网络,则服务器提供不同的地址,而isc-dhcp-client只发送一个NAK,因为它没有被提供请求的地址.
基本上,我想要的是
客户:“你好,我可以拥有10.23.33.254”
服务器:“不,你不能.在这里,有192.168.1.23而不是”
客户:“好的,谢谢”
相反,正在发生的事情是
客户:“你好,有192.168.1.23而不是”
客户:“那不是我想要的.我可以拥有10.23.33.254吗?”
服务器:“不,你不能……”(永远重复这个循环)
任何人都知道我想要的是不可能的,没有写我自己的DHCP客户端?
只需构建一个最小的租约文件,该文件具有过期的续订和重新绑定(以避免一些重试)但仍然是未来的过期日期(不会立即忘记它并立即尝试发现而不是请求,并且如果没有则使用此IP DHCP服务器完全回答).保持此文件不变,并在每次运行dhclient之前复制它.
这是一个来自我的stretch-amd64容器的最小文件,只要DHCP服务器(此处为dnsmasq)没有为此客户端设置的其他租约就可以工作.在运行dhclient之前,只需将其复制到租约文件中即可.
lease { interface "eth0"; fixed-address 10.0.3.222; renew 0 2000/1/1 00:00:01; rebind 0 2000/01/01 00:00:01; expire 0 2038/1/1 00:00:01; }
尝试使用服务器10.0.3.0/24并且不知道此客户端的LAN服务器的局域网:
# dhclient -v eth0 Internet Systems Consortium DHCP Client 4.3.5 Copyright 2004-2016 Internet Systems Consortium. All rights reserved. For info,please visit https://www.isc.org/software/dhcp/ Listening on LPF/eth0/xx:xx:xx:xx:xx:xx Sending on LPF/eth0/xx:xx:xx:xx:xx:xx Sending on Socket/fallback DHCPREQUEST of 10.0.3.222 on eth0 to 255.255.255.255 port 67 DHCPACK of 10.0.3.222 from 10.0.3.1 bound to 10.0.3.222 -- renewal in 1486 seconds.
新租约文件/var/lib/dhcp/dhclient.leases:
lease { interface "eth0"; fixed-address 10.0.3.222; renew 6 2000/01/01 00:00:01; rebind 6 2000/01/01 00:00:01; expire never; } lease { interface "eth0"; fixed-address 10.0.3.222; option subnet-mask 255.255.255.0; option routers 10.0.3.1; option dhcp-lease-time 3600; option dhcp-message-type 5; option domain-name-servers 10.0.3.1; option dhcp-server-identifier 10.0.3.1; option dhcp-renewal-time 1800; option broadcast-address 10.0.3.255; option dhcp-rebinding-time 3150; option host-name "stretch-amd64"; renew 0 2017/10/29 19:57:41; rebind 0 2017/10/29 20:24:34; expire 0 2017/10/29 20:32:04; }
在IP范围之外尝试:
Listening on LPF/eth0/xx:xx:xx:xx:xx:xx Sending on LPF/eth0/xx:xx:xx:xx:xx:xx Sending on Socket/fallback DHCPREQUEST of 10.0.4.222 on eth0 to 255.255.255.255 port 67 DHCPREQUEST of 10.0.4.222 on eth0 to 255.255.255.255 port 67 DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4 DHCPREQUEST of 10.0.3.249 on eth0 to 255.255.255.255 port 67 DHCPOFFER of 10.0.3.249 from 10.0.3.1 DHCPACK of 10.0.3.249 from 10.0.3.1 bound to 10.0.3.249 -- renewal in 1411 seconds.
这个DHCP服务器似乎没有发送NAK,但无论如何我确信你明白了,它确实有效.
如果没有DHCP服务器,经过一段时间后,dhclient将配置IP,因为它在租约和daemonize中没有过期.如果没有其他选项(广播…),这将是/ 32,因为信息不可用.如果需要,在“模板”租约文件中添加其他值.这将是:
option subnet-mask 255.255.255.0; option routers 10.0.3.1; option domain-name-servers 10.0.3.1; option broadcast-address 10.0.3.255;
在这种情况下运行dhclient时:
[…]
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 12 No DHCPOFFERS received. Trying recorded lease 10.0.3.222 PING 10.0.3.1 (10.0.3.1) 56(84) bytes of data. --- 10.0.3.1 ping statistics --- 1 packets transmitted,1 received,0% packet loss,time 0ms rtt min/avg/max/mdev = 0.240/0.240/0.240/0.000 ms bound: immediate renewal. DHCPREQUEST of 10.0.3.222 on eth0 to 255.255.255.255 port 67 root@stretch-amd64:~#