Linux

測試DHCP服務的命令行程序

  • March 15, 2018

是否有一個簡單的類似 ping 的命令來測試 DHCP 服務是否在網路上執行?…在 Linux 上

即使您不使用 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

引用自:https://serverfault.com/questions/171744