当一个Linux Mint 20 虚拟机通过以下方式向家庭 LAN 路由器 DHCP 请求网络配置isc-dhcp 客户端使用库存/etc/dhcp/dhclient.conf
配置文件一切运行正常:
(顺便说一下,192.168.0.1 是主路由器 - Sercomm H500-s - 启用了 DHCP 服务器,而 192.168.0.98 是另一个充当网桥的路由器,DHCP 服务器已禁用)
root@PC-a01-01:~# dhclient -v
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on Socket/fallback
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0xaf2ff163)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x63f12faf)
DHCPNAK from 192.168.0.98 (xid=0xaf2ff163)
DHCPACK of 192.168.0.123 from 192.168.0.1 (xid=0xaf2ff163)
cmp: EOF on /tmp/tmp.wezYhIRa8t which is empty
bound to 192.168.0.123 -- renewal in 41497 seconds.
但是当我尝试请求特定的 IP 地址时,dhclient 陷入了无限循环:
/etc/dhcp/dhclient.conf
interface "enp0s3" {
send host-name = gethostname();
send dhcp-requested-address 192.168.0.199;
}
dhclient -4 -v -cf /etc/dhcp/dhclient.conf
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on Socket/fallback
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x48fb1700)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 5 (xid=0x48fb1700)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x17fb48)
DHCPNAK from 192.168.0.98 (xid=0x48fb1700)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x17fb48)
DHCPNAK from 192.168.0.98 (xid=0x48fb1700)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x17fb48)
DHCPNAK from 192.168.0.98 (xid=0x48fb1700)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x43eff0c)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0xcff3e04)
DHCPNAK from 192.168.0.98 (xid=0x43eff0c)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0xcff3e04)
DHCPNAK from 192.168.0.98 (xid=0x43eff0c)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0xcff3e04)
DHCPNAK from 192.168.0.98 (xid=0x43eff0c)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x4ab08339)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x3983b04a)
DHCPNAK from 192.168.0.98 (xid=0x4ab08339)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x3983b04a)
DHCPNAK from 192.168.0.98 (xid=0x4ab08339)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x3983b04a)
DHCPNAK from 192.168.0.98 (xid=0x4ab08339)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x7e5bbe2b)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x2bbe5b7e)
DHCPNAK from 192.168.0.98 (xid=0x7e5bbe2b)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x2bbe5b7e)
DHCPNAK from 192.168.0.98 (xid=0x7e5bbe2b)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x2bbe5b7e)
DHCPNAK from 192.168.0.98 (xid=0x7e5bbe2b)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x2bbe5b7e)
DHCPNAK from 192.168.0.98 (xid=0x7e5bbe2b)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x32f5b011)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x32f5b011)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x11b0f532)
DHCPNAK from 192.168.0.98 (xid=0x32f5b011)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x11b0f532)
DHCPNAK from 192.168.0.98 (xid=0x32f5b011)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x11b0f532)
DHCPNAK from 192.168.0.98 (xid=0x32f5b011)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x77dca0a)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0xaca7d07)
DHCPNAK from 192.168.0.98 (xid=0x77dca0a)
^C
我还尝试了以下步骤,但保持/etc/dhcp/dhclient.conf
其库存/正品状态,但没有成功:
rm -fr /var/lib/dhcp/dhclient.leases
nano -w /var/lib/dhcp/dhclient.leases
lease {
interface "enp0s3";
fixed-address 192.168.0.145;
renew 0 2000/1/1 00:00:01;
rebind 0 2000/01/01 00:00:01;
expire 0 2038/1/1 00:00:01;
}
dhclient -4 -v -cf /etc/dhcp/dhclient.conf
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on Socket/fallback
DHCPREQUEST for 192.168.0.145 on enp0s3 to 255.255.255.255 port 67 (xid=0x1935a408)
DHCPNAK from 192.168.0.1 (xid=0x8a43519)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0xdf48dc0f)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0xfdc48df)
DHCPNAK from 192.168.0.98 (xid=0xdf48dc0f)
DHCPACK of 192.168.0.123 from 192.168.0.1 (xid=0xdf48dc0f)
cmp: EOF on /tmp/tmp.RmsqemfUfM which is empty
bound to 192.168.0.123 -- renewal in 39093 seconds.
nmap 扫描探测网络中是否存在单个 DHCP 服务器:
nmap --script broadcast-dhcp-discover
Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-18 21:38 CEST
Pre-scan script results:
| broadcast-dhcp-discover:
| Response 1 of 1:
| IP Offered: 192.168.0.124
| DHCP Message Type: DHCPOFFER
| Server Identifier: 192.168.0.1
| IP Address Lease Time: 1d00h00m00s
| Subnet Mask: 255.255.255.0
| Router: 192.168.0.1
| Domain Name Server: 176.103.130.130, 212.166.210.83, 212.166.132.96
| Hostname: PWiFi
| Domain Name: pperis.ddns.net
| Renewal Time Value: 12h00m00s
|_ Rebinding Time Value: 21h00m00s
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 2.93 seconds
以下是我关闭 192.168.0.98 路由器后得到的响应:
dhclient -4 -v -cf /etc/dhcp/dhclient.conf
rm -fr /var/lib/dhcp/dhclient.leases
# dhclient -4 -v -cf /etc/dhcp/dhclient.conf
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on LPF/enp0s3/08:00:27:f1:e3:2c
Sending on Socket/fallback
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0xe7d65802)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x258d6e7)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x258d6e7)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x258d6e7)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x33d20f05)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x50fd233)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x50fd233)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x50fd233)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x50fd233)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0xf3558362)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x628355f3)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x628355f3)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x628355f3)
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0xcd2ad06d)
DHCPOFFER of 192.168.0.123 from 192.168.0.1
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x6dd02acd)
DHCPREQUEST for 192.168.0.123 on enp0s3 to 255.255.255.255 port 67 (xid=0x6dd02acd)
^C
这是/etc/dhcp/dhclient.conf
先前输出的配置文件:
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name = gethostname();
send dhcp-requested-address 192.168.0.189;
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;
interface "enp0s3" {
send host-name = gethostname();
send dhcp-client-identifier 08:00:27:f1:e3:2c;
send dhcp-requested-address 192.168.0.189;
}
有谁有能力或有解释力来理解发生了什么吗?我还想能够请求一个特定的 IP 地址,如果它已被使用,则获取另一个。
提前谢谢您!