SkillPilotAI

dhcping and dhcpdump

dhcping is a ping-style health check for a DHCP server: it sends a request for one known client and exits 0 if an answer comes, 1 if not. dhcpdump passively listens on ports 67/68 and decodes every DHCP packet field by field, which is how you spot a rogue server.

80.1 Why is it used?

  • dhcping: monitoring (cron/Nagios) to alert 'DHCP DOWN' from the exit code.
  • dhcpdump: see exactly what each DHCP message carries (offered IP, lease, router, DNS, server id).
  • dhcpdump: catch a rogue DHCP server handing out a wrong gateway.
  • Linux: apt/dnf packages, both need root. macOS does not package them: use tcpdump -vv port 67 or 68.

80.2 How it works

dhcping: a health check for one known client
  1. 1.Monitor host 192.168.100.10 runs dhcping -c -s -h

  2. 2.A DHCPREQUEST goes through the Docker bridge straight to server 192.168.100.2

  3. 3.The server has a fixed-address entry for that MAC and replies DHCPACK

  4. 4.dhcping prints 'Got answer from' and exits 0

  5. 5.Default mode then sends DHCPRELEASE so the lease stays free

  6. 6.Wrong/dead server (.99): no answer after 3 s, exit 1 -> alert

80.3 dhcping: -c, -s, -h

  • -c client IP (it asks for this address and receives the answer), -s server IP, -h client MAC: all three are required.
  • Read the host's own MAC from /sys/class/net/eth0/address instead of typing it.
  • The server needs a fixed-address host entry for that MAC, and you need root.
Terminal
dhcping -c 192.168.100.10 \  -s 192.168.100.2 \  -h $(cat /sys/class/net/eth0/address); \  echo exit=$?
Output
$ cat /sys/class/net/eth0/address02:42:c0:a8:64:0a$ dhcping -c 192.168.100.10 \  -s 192.168.100.2 \  -h $(cat /sys/class/net/eth0/address); \  echo exit=$?Got answer from: 192.168.100.2exit=0

80.4 dhcping: verbose and modes

  • -v is verbose but in version 1.2 the output is unchanged; -V prints a hex dump and decoded fields of every packet.
  • -r (default) uses DHCPREQUEST then DHCPRELEASE: message types 3, 5, 7 in the server log.
  • -i sends DHCPINFORM: no lease is taken or released, the server just ACKs (only when it is authoritative for the subnet).
Terminal
dhcping -V -c 192.168.100.10 -s 192.168.100.2 -h 02:42:c0:a8:64:0adhcping -r -c 192.168.100.10 -s 192.168.100.2 -h 02:42:c0:a8:64:0adhcping -i -v -c 192.168.100.10 -s 192.168.100.2 -h 02:42:c0:a8:64:0adocker logs n080-dhcp 2>&1 | grep DHCP     # host: server log
Output
$ dhcping -V -c 192.168.100.10 \  -s 192.168.100.2 -h 02:42:c0:a8:64:0asetuprequestpacket 250 bytes01 01 06 00 43 f3 f0 6a 00 00 00 00 c0 a8 64 0a00 00 00 00 00 00 00 00 00 00 00 00 02 42 c0 a8op: 1ciaddr: 192.168.100.10    DHCP message type: 3 (DHCPREQUEST)readGot answer from: 192.168.100.2packet 300 bytes02 01 06 00 43 f3 f0 6a 00 00 00 00 c0 a8 64 0aop: 2yiaddr: 192.168.100.10    DHCP message type: 5 (DHCPACK)    Server identifier: 192.168.100.2    Router: 192.168.100.1release    DHCP message type: 7 (DHCPRELEASE)close$ docker logs n080-dhcp 2>&1 | grep DHCP      # after -rDHCPREQUEST for 192.168.100.10 from 02:42:c0:a8:64:0a via eth0DHCPACK on 192.168.100.10 to 02:42:c0:a8:64:0a via eth0DHCPRELEASE of 192.168.100.10 from 02:42:c0:a8:64:0a via eth0 (not found)$ docker logs n080-dhcp 2>&1 | grep DHCP      # after -iDHCPINFORM from 192.168.100.10 via eth0DHCPACK to 192.168.100.10 (02:42:c0:a8:64:0a) via eth0

80.5 dhcping: failures, timeout and monitoring

  • Unknown MAC: server log says 'unknown lease', screen says 'no answer'.
  • -g puts a relay gateway IP in the packet, but the server then sends the ACK to that gateway: with no relay you get no answer.
  • -t 10 waits 10 s (default 3 s); -q is quiet, only the exit code.
  • One-liner for cron: dhcping -q ... || echo 'DHCP DOWN'.
Terminal
dhcping -c 192.168.100.10 -s 192.168.100.2 -h 01:02:03:04:05:06time dhcping -t 10 -c 192.168.100.10 -s 192.168.100.99 -h 02:42:c0:a8:64:0adhcping -q -t 5 -s 192.168.100.99 \  -c 192.168.100.10 -h 02:42:c0:a8:64:0a \  || echo 'DHCP DOWN'
Output
$ dhcping -c 192.168.100.10 \  -s 192.168.100.2 -h 01:02:03:04:05:06no answer$ docker logs n080-dhcp 2>&1 | grep DHCPDHCPREQUEST for 192.168.100.10 from 01:02:03:04:05:06 via eth0: unknown lease 192.168.100.10.$ time dhcping -t 10 -c 192.168.100.10 \  -s 192.168.100.99 -h 02:42:c0:a8:64:0ano answerreal    0m10.015s$ dhcping -q -t 5 -s 192.168.100.99 \  -c 192.168.100.10 -h 02:42:c0:a8:64:0a \  || echo 'DHCP DOWN'DHCP DOWN
dhcping optionMeaning
-c IPClient IP (answer comes here)
-s IPDHCP server IP
-h MACClient MAC (up to 16 octets)
-rDHCPREQUEST (default) + RELEASE
-iDHCPINFORM: no lease taken
-v / -VVerbose (same output in 1.2) / hex + options
-qQuiet: exit code only
-t NWait max N seconds (default 3)
-g IPRelay gateway IP (ACK goes to the gateway)

80.6 dhcpdump: live decoding

dhcpdump: the four DORA packets on the wire
  1. 1.dhcpdump -i eth0 runs on client 192.168.100.20; dhclient asks for an IP

  2. 2.DISCOVER broadcast (option 53 = 1) is heard by the whole LAN

  3. 3.Server sends OFFER (53 = 2) with YIADDR 192.168.100.100

  4. 4.Client broadcasts REQUEST (53 = 3)

  5. 5.Server confirms with ACK (53 = 5); dhcpdump only reads a copy

Terminal
timeout 12 dhcpdump -i eth0 > live.txt &dhclient -v -1 eth0cat live.txt
Output
$ dhclient -v -1 eth0DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3DHCPOFFER of 192.168.100.100 from 192.168.100.2DHCPREQUEST for 192.168.100.100 on eth0 to 255.255.255.255 port 67DHCPACK of 192.168.100.100 from 192.168.100.2bound to 192.168.100.100 -- renewal in 41604 seconds.$ cat live.txt  TIME: 2026-11-08 22:11:05.442    IP: 192.168.100.2 (2:42:c0:a8:64:2) > 192.168.100.100 (2:42:c0:a8:64:14)    OP: 2 (BOOTPREPLY)CIADDR: 0.0.0.0YIADDR: 192.168.100.100CHADDR: 02:42:c0:a8:64:14:00:00:00:00:00:00:00:00:00:00OPTION:  53 (  1) DHCP message type         5 (DHCPACK)OPTION:  54 (  4) Server identifier         192.168.100.2OPTION:  51 (  4) IP address leasetime      86400 (24h)OPTION:   1 (  4) Subnet mask               255.255.255.0OPTION:   3 (  4) Routers                   192.168.100.1OPTION:   6 (  8) DNS server                8.8.8.8,1.1.1.1
Field / optionMeaning
OP1 = BOOTPREQUEST (client), 2 = BOOTPREPLY (server)
CIADDR / YIADDRClient's current IP / IP given to the client
GIADDR / CHADDRRelay agent IP / client hardware address
Option 53Message type: 1 Discover, 2 Offer, 3 Request, 5 ACK, 7 Release
Option 54Server identifier
Option 51 / 3 / 6Lease time / router / DNS servers

80.7 dhcpdump: short view, MAC filter and pcap fallback

  • The real output has two spaces after 'OPTION:', so grep 'OPTION: 53' misses the type; use 'OPTION: +53'.
  • -h REGEX filters on CHADDR: the client's own MAC caught 7 packets; '^aa:bb:cc' gave 0 lines.
  • -r (read pcap) and -H (hex dump) arrived in 1.9; Debian 12 ships 1.8 ('unknown option'). Fallback: tcpdump -w, then tcpdump -n -vv -r.
Terminal
grep -E 'TIME|OPTION: +53|YIADDR' live.txttimeout 10 dhcpdump -i eth0 -h '^02:42:c0:a8:64:14' > h-match.txt &timeout 12 tcpdump -n -i eth0 -w dhcp.pcap port 67 or port 68 &tcpdump -n -vv -r dhcp.pcap -c 1
Output
$ grep -E 'TIME|OPTION: +53|YIADDR' live.txt  TIME: 2026-11-08 22:11:04.442YIADDR: 0.0.0.0OPTION:  53 (  1) DHCP message type         1 (DHCPDISCOVER)  TIME: 2026-11-08 22:11:05.442YIADDR: 192.168.100.100OPTION:  53 (  1) DHCP message type         2 (DHCPOFFER)  TIME: 2026-11-08 22:11:05.442YIADDR: 0.0.0.0OPTION:  53 (  1) DHCP message type         3 (DHCPREQUEST)  TIME: 2026-11-08 22:11:05.442YIADDR: 192.168.100.100OPTION:  53 (  1) DHCP message type         5 (DHCPACK)$ dhcpdump -r dhcp.pcapdhcpdump: r: unknown optionUsage: $0 <-i interface> [-h macaddress]$ tcpdump -n -vv -r dhcp.pcap -c 1    0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 02:42:c0:a8:64:14, length 300, xid 0xba549b38, Flags [none] (0x0000)      Client-Ethernet-Address 02:42:c0:a8:64:14        DHCP-Message (53), length 1: Discover        Hostname (12), length 6: "client"

80.8 Recipe: catching a rogue DHCP server

Rogue DHCP: two servers, two OFFERs
  1. 1.A rogue server 192.168.100.3 appears on the lab LAN

  2. 2.The client's Discover broadcast reaches both servers

  3. 3.Real server offers 192.168.100.100 with router 192.168.100.1

  4. 4.Rogue offers 192.168.100.210 with router 192.168.100.3 (itself)

  5. 5.dhcpdump shows two different Server identifiers: red flag

If the client takes the rogue offer, all its traffic goes through the attacker

Terminal
timeout 10 dhcpdump -i eth0 > rogue.txt &dhclient -v -1 eth0grep -i 'Server identifier' rogue.txt | sort | uniq -cgrep -E 'IP:|OPTION:  53|YIADDR|OPTION:   3' rogue.txt
Output
$ grep -i 'Server identifier' rogue.txt \  | sort | uniq -c      4 OPTION:  54 (  4) Server identifier         192.168.100.2      1 OPTION:  54 (  4) Server identifier         192.168.100.3$ grep -E \  'IP:|OPTION:  53|YIADDR|OPTION:   3' \  rogue.txt    IP: 192.168.100.2 (2:42:c0:a8:64:2) > 192.168.100.100 (2:42:c0:a8:64:14)YIADDR: 192.168.100.100OPTION:  53 (  1) DHCP message type         2 (DHCPOFFER)OPTION:   3 (  4) Routers                   192.168.100.1    IP: 192.168.100.2 (2:42:c0:a8:64:2) > 192.168.100.100 (2:42:c0:a8:64:14)YIADDR: 192.168.100.100OPTION:  53 (  1) DHCP message type         5 (DHCPACK)OPTION:   3 (  4) Routers                   192.168.100.1    IP: 192.168.100.3 (8a:56:ab:18:1b:b1) > 255.255.255.255 (ff:ff:ff:ff:ff:ff)YIADDR: 192.168.100.210OPTION:  53 (  1) DHCP message type         2 (DHCPOFFER)OPTION:   3 (  4) Routers                   192.168.100.3
  • Here the rogue OFFER arrived late, so the client picked the real server, but next time it might win.
  • Run this test only on a network you own or have permission for.

80.9 Common mistakes

  • Running dhcping with a MAC the server does not know: 'unknown lease' looks like an outage.
  • Using -g without a real relay: the ACK goes to the gateway and you see 'no answer'.
  • Grepping 'OPTION: 53' with one space and losing the message type.
  • Thinking dhcpdump blocks or slows DHCP: it is passive. dhcping is active (real REQUEST + RELEASE), so use a dedicated monitoring MAC in production.

80.10 Interview tips

  • Health check: dhcping -q -t 5 -c IP -s SERVER -h MAC || alert; exit 0 = answer, 1 = no answer.
  • dhcping exit 1 but the server process is up: read the server log (fixed entry removed, relay or firewall drop).
  • Clients get a wrong gateway: run dhcpdump, compare option 54 (Server identifier) and option 3 (router); two servers = rogue.
  • Prevent rogues with DHCP snooping: OFFERs allowed only from the trusted port.