是否有一个简单的类似 ping 的命令来测试 DHCP 服务是否在网络上运行?...在 Linux 上
答案1
即使你不使用 Nagios 监控服务器,你也可以使用 grep检查DHCP二进制文件或从源代码编译它并使用检查来测试 DHCP 服务器。例如
./check_dhcp -v -s <dhcp_server_address> -r <expected_ip_address> -m <mac_address_touse>
答案2
基于这个答案,假设你已经安装了 nmap( sudo apt install nmap
):
sudo nmap --script broadcast-dhcp-discover
-e $interface
如果您有多个网络接口,请添加该选项。(例如nmap --script broadcast-dhcp-discover -e eth0
:)
示例输出:
Starting Nmap 7.01 ( https://nmap.org ) at 2017-09-27 17:40 CEST
Pre-scan script results:
| broadcast-dhcp-discover:
| Response 1 of 1:
| IP Offered: 192.168.81.94
| DHCP Message Type: DHCPOFFER
| Server Identifier: 192.168.81.2
| IP Address Lease Time: 5m00s
| Subnet Mask: 255.255.255.0
| Router: 192.168.81.2
| Domain Name Server: 192.168.81.2
| Domain Name: example.lan
| NTP Servers: 192.168.81.10, 192.168.81.2
| NetBIOS Name Server: 192.168.81.10
|_ NetBIOS Node Type: 8
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.66 seconds
或者在另一个网络上使用 nmap v. 6 获得此输出:
Starting Nmap 6.00 ( http://nmap.org ) at 2017-09-27 17:42 CEST
Pre-scan script results:
| broadcast-dhcp-discover:
| IP Offered: 192.168.4.101
| DHCP Message Type: DHCPOFFER
| Server Identifier: 192.168.4.1
| IP Address Lease Time: 7 days, 0:00:00
| Subnet Mask: 255.255.255.0
| Time Offset: 7200
| Router: 192.168.4.1
| Domain Name Server: 208.91.112.53, 208.91.112.52
| Renewal Time Value: 3 days, 12:00:00
|_ Rebinding Time Value: 6 days, 3:00:00
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 1.15 seconds
答案3
dhcpcd
或者您可以在测试模式下尝试:
dhcpcd -T eth0
答案4
为什么不直接发出 DHCP 请求?
dhclient
对于详细输出使用:
dhclient-v