DHCP: the DORA process
DHCP (Dynamic Host Configuration Protocol) automatically gives a device its IP address, subnet mask, gateway and DNS server. It does this in four messages called DORA: Discover, Offer, Request, ACK.
78.1 Why is it used?
- A new laptop on the office Wi-Fi or LAN has no IP and does not know the gateway or DNS.
- Setting all this by hand on 500 devices is impossible and error-prone (duplicate IPs).
- Changing a gateway or DNS server happens in one place: the DHCP server.
- IPs are rented (leased), so addresses of devices that leave go back to the pool.
78.2 How it works: DORA
- Step 1
1.D Discover: laptop broadcasts 0.0.0.0:68 -> 255.255.255.255:67 with its MAC (chaddr)
- Step 2
2.The switch floods it; the phone ignores it, only the DHCP server answers
- Step 3
3.O Offer: server 192.168.98.2 offers 192.168.98.119 + mask, router 192.168.98.1, lease 120 s
- Step 4
4.R Request: laptop broadcasts 'I want 192.168.98.119' with server-id 192.168.98.2
- Step 5
5.A ACK: server confirms and writes MAC, IP, expiry into its lease table
- Step 6
6.Laptop configures IP and gateway on its interface
Discover and Request are broadcasts because the client has no IP yet
- DHCP runs over UDP: server port 67, client port 68.
- With two DHCP servers the client gets two Offers and usually takes the first.
- Request is broadcast even though the client knows the server, so other servers learn their offer was declined and return that IP to their pool.
| Message | Direction | Sent as | Purpose |
|---|---|---|---|
| Discover (1) | Client -> all | Broadcast | Find a DHCP server |
| Offer (2) | Server -> client | From server | Offer a free IP + options |
| Request (3) | Client -> all | Broadcast (unicast when renewing) | Ask for the offered IP |
| ACK (5) | Server -> client | From server | Confirm the lease |
| Release (7) | Client -> server | Unicast | Give the IP back |
78.3 dnsmasq DHCP server (lab)
- dhcp-range: pool 192.168.98.100-120 with a 2-minute lease (short, to see renewal quickly).
- dhcp-option: gateway 192.168.98.1 and DNS 1.1.1.1.
- dhcp-host: a reservation for the printer's MAC.
port=0interface=eth0dhcp-authoritativeno-pinglog-dhcpdhcp-range=192.168.98.100,192.168.98.120,2mdhcp-option=option:router,192.168.98.1dhcp-option=option:dns-server,1.1.1.1dhcp-host=02:78:00:00:00:20,192.168.98.50dhcp-leasefile=/tmp/n078.leases78.4 The four real DORA packets
# n078-dhcp: capture port 67 and 68tcpdump -ni eth0 -w dora.pcap port 67 or 68# n078-pc: DHCP client, release on exitudhcpc -f -i eth0 -R -x hostname:pcip -4 addr show eth0 | grep inet# n078-dhcp: read the capturetshark -r dora.pcappc$ udhcpc -f -i eth0 -R -x hostname:pcudhcpc: started, v1.36.1udhcpc: broadcasting discoverudhcpc: broadcasting select for 192.168.98.119, server 192.168.98.2udhcpc: lease of 192.168.98.119 obtained from 192.168.98.2, lease time 120pc$ ip -4 addr show eth0 | grep inet inet 192.168.98.119/25 brd 192.168.98.127 scope global eth0dhcp$ tshark -r dora.pcap1 0.000000 0.0.0.0 → 255.255.255.255 DHCP 342 DHCP Discover - Transaction ID 0x587efd182 0.000700 192.168.98.2 → 192.168.98.119 DHCP 342 DHCP Offer - Transaction ID 0x587efd183 0.039959 0.0.0.0 → 255.255.255.255 DHCP 342 DHCP Request - Transaction ID 0x587efd184 0.069197 192.168.98.2 → 192.168.98.119 DHCP 342 DHCP ACK - Transaction ID 0x587efd18- All four share Transaction ID 0x587efd18; the whole DORA took about 70 ms.
78.5 Lease time: T1, T2, release
- Step 1
1.ACK: lease starts (lab: 120 s)
- Step 2
2.T1 = 50% (60 s): unicast Request to the same server to renew
- Step 3
3.T2 = 87.5% (105 s): if no answer, broadcast to rebind with any server
- Step 4
4.Lease expiry: stop using the IP, start DORA again
A successful renew restarts the timers
tcpdump -nv -r dora.pcap -c 1 src port 67dhcp$ tcpdump -nv -r dora.pcap -c 1 src port 67 192.168.98.2.67 > 192.168.98.119.68: BOOTP/DHCP, Reply, length 300, xid 0x587efd18, Flags [none] Your-IP 192.168.98.119 DHCP-Message (53), length 1: Offer Server-ID (54), length 4: 192.168.98.2 Lease-Time (51), length 4: 120 RN (58), length 4: 60 RB (59), length 4: 105 Default-Gateway (3), length 4: 192.168.98.1dhcp$ tshark -r dora.pcap4 0.069197 192.168.98.2 → 192.168.98.119 DHCP 342 DHCP ACK - Transaction ID 0x587efd185 60.124007 192.168.98.119 → 192.168.98.2 DHCP 342 DHCP Request - Transaction ID 0x587efd186 60.130031 192.168.98.2 → 192.168.98.119 DHCP 342 DHCP ACK - Transaction ID 0x587efd18pc$ pkill udhcpc; sleep 2; ip -4 addr show eth0 | grep inet || echo 'no IPv4 address'no IPv4 addressdhcp$ tshark -r dora.pcap7 84.939464 192.168.98.119 → 192.168.98.2 DHCP 342 DHCP Release - Transaction ID 0x3854e27d- Option 58 (RN, renewal) = T1 = 60 s, option 59 (RB, rebinding) = T2 = 105 s.
- Frames 5-6 at 60 s are the unicast renew; frame 7 is the Release sent when udhcpc -R was stopped.
78.6 Reservation (printer)
- A printer needs the same IP every time because everyone prints to that address.
- dhcp-host binds MAC 02:78:00:00:00:20 to 192.168.98.50: the printer does a normal DORA but always gets the reserved IP.
udhcpc -q -i eth0 -x hostname:printercat /tmp/n078.leasesprinter$ udhcpc -q -i eth0 -x hostname:printerudhcpc: broadcasting discoverudhcpc: broadcasting select for 192.168.98.50, server 192.168.98.2udhcpc: lease of 192.168.98.50 obtained from 192.168.98.2, lease time 120dhcp$ cat /tmp/n078.leases1794175299 02:78:00:00:00:20 192.168.98.50 printer 01:02:78:00:00:00:20| Point | Static IP | Reservation |
|---|---|---|
| Where set | Manually on the device | On the DHCP server (MAC -> IP) |
| Talks to DHCP | Never | Yes, normal DORA |
| Gateway/DNS change | Edit every device | Change once on the server |
78.7 DHCP relay and giaddr
- Step 1
1.Branch PC (192.168.98.128/25) broadcasts Discover
- Step 2
2.The broadcast stops at the router, so the router runs a DHCP relay agent
- Step 3
3.The relay turns it into unicast to 192.168.98.2 and sets giaddr = 192.168.98.130
- Step 4
4.The server uses giaddr to pick the branch pool
- Step 5
5.The Offer returns via the relay to the branch PC
# n078-relay: /etc/relay.confport=0dhcp-relay=192.168.98.130,192.168.98.2# n078-pc2udhcpc -q -i eth0 -x hostname:pc2ip route# n078-dhcptshark -r relay.pcap -T fields -e dhcp.option.dhcp -e dhcp.ip.relay -e dhcp.ip.yourpc2$ udhcpc -q -i eth0 -x hostname:pc2udhcpc: broadcasting discoverudhcpc: broadcasting select for 192.168.98.209, server 192.168.98.2udhcpc: lease of 192.168.98.209 obtained from 192.168.98.2, lease time 600pc2$ ip routedefault via 192.168.98.129 dev eth0 metric 209dhcp$ tshark -r relay.pcap -T fields -e dhcp.option.dhcp -e dhcp.ip.relay -e dhcp.ip.your1 192.168.98.130 0.0.0.02 192.168.98.130 192.168.98.2093 192.168.98.130 0.0.0.05 192.168.98.130 192.168.98.20978.8 Rogue DHCP and DHCP snooping
- A rogue DHCP server (an attacker's box or an employee's home router) also sends Offers.
- The client takes the first Offer; if the rogue sets itself (192.168.98.66) as gateway, all traffic flows through it: man-in-the-middle.
- Fix: DHCP snooping on the switch. Only the real server's port is trusted; Offers from untrusted ports are dropped, and a binding table is built.
- Detect: nmap --script broadcast-dhcp-discover lists every server that answers (own network only).
nmap --script broadcast-dhcp-discover -e eth0$ nmap --script broadcast-dhcp-discover -e eth0Pre-scan script results:| broadcast-dhcp-discover:| Response 1 of 2:| IP Offered: 192.168.98.105| Server Identifier: 192.168.98.2| Router: 192.168.98.1| Response 2 of 2:| IP Offered: 192.168.98.77| Server Identifier: 192.168.98.66|_ Router: 192.168.98.6678.9 Common mistakes
- Calling a reservation a static IP: with a reservation the device still runs DORA.
- Expecting DHCP broadcasts to reach a server in another subnet without a relay.
- Forgetting T1/T2: renewal starts at 50% of the lease, not at expiry.
- Not enabling DHCP snooping: without it, any plugged-in router can hand out a fake gateway.
78.10 Interview tips
- DHCP = UDP 67 (server) / 68 (client); DORA = Discover, Offer, Request, ACK; Discover and Request are broadcasts.
- 8-hour lease: T1 at 4 h (unicast renew), T2 at 7 h (broadcast rebind).
- Other subnets: a relay agent forwards as unicast and fills giaddr so the server picks the right pool.
- Rogue DHCP -> man-in-the-middle; prevent with DHCP snooping (trusted server port).