Answers:
即使您不使用Nagios监控服务器,也可以grep check_dhcp二进制文件或从源代码对其进行编译,然后使用该检查来测试DHCP服务器。例如
./check_dhcp -v -s <dhcp_server_address> -r <expected_ip_address> -m <mac_address_touse>
根据此答案,假设您已安装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
dhcpdump
非常适合在网络上嗅探和显示DHCP数据包。
例如
# dhcpdump -i eth0
---------------------------------------------------------------------------
TIME: 2015-11-27 11:41:37.379
IP: 0.0.0.0 (0:11:b9:5:0:b8) > 255.255.255.255 (ff:ff:ff:ff:ff:ff)
OP: 1 (BOOTPREQUEST)
HTYPE: 1 (Ethernet)
HLEN: 6
HOPS: 0
XID: abce9327
SECS: 0
FLAGS: 0
CIADDR: 0.0.0.0
YIADDR: 0.0.0.0
SIADDR: 0.0.0.0
GIADDR: 0.0.0.0
CHADDR: 00:11:b9:05:00:b8:00:00:00:00:00:00:00:00:00:00
SNAME: .
FNAME: .
OPTION: 53 ( 1) DHCP message type 1 (DHCPDISCOVER)
OPTION: 57 ( 2) Maximum DHCP message size 576
OPTION: 55 ( 4) Parameter Request List 1 (Subnet mask)
3 (Routers)
28 (Broadcast address)
6 (DNS server)
---------------------------------------------------------------------------
您可以将其与其他工具结合使用以进行DHCP请求,或者仅用于监视PC /设备查询DHCP。
brew install dhcpdump
。
我之前写了一个DHCP测试客户端程序,可在Windows和POSIX上运行:
ldc2
)来获取静态的二进制文件ldc2 -link-defaultlib-shared=false -static -L=-lphobos2-ldc -L=-lz dhcptest.d
为什么不仅仅发出DHCP请求?
dhclient
对于详细输出,请使用:
dhclient -v
-n
在Ubuntu 14 LTS上的ISC DHCP客户端v4.2.4上,选项似乎已损坏?
-n
您没有做。
如果您使用nagios,则可以使用check_dhcp对其进行监视