How DHCP Works, Packet by Packet
This walkthrough uses three captures from the late Nick Russo's free packet-capture library. They are in the Network Services archive, netsrv_pcap.zip, under netsrv_pcap/dhcp/: dhcp_v4_basic.pcapng, dhcp_v4_relay.pcapng, and dhcp_v4_renewal.pcapng. The archive is preserved by the Internet Archive, with the rest of the library listed on his job aid page. We decoded the captures with VisualEther, which turns a Wireshark PCAP into a sequence diagram with a plain-English caption on every message.
DHCP (Dynamic Host Configuration Protocol) is how a device that has just joined a network gets an IP address, a subnet mask, a default router, and DNS servers, without anyone typing them in. Almost every laptop, phone, and home router uses it every day, yet the exchange is over in under a millisecond and rarely seen.
The three captures each show one part of the protocol:
- A client and server on the same LAN run the four-message exchange known as DORA (Discover, Offer, Request, ACK), and later the client gives its address back.
- A relay agent carries the same exchange to a server on another network, across a VPN tunnel.
- A short 60-second lease is renewed twice, which shows how a client keeps its address.
Each capture is drawn as an annotated sequence diagram. Each participant gets a lane, and each DHCP message is an arrow, numbered as in Wireshark and captioned with what it does. Every diagram comes in three forms: an interactive viewer, an HTML page, and a printable PDF. In the viewer and the HTML page, clicking any message opens its full Wireshark field tree.
💡 Read the walkthrough and a diagram side by side: open the interactive diagram in a split-screen window, or open the HTML version in a new tab and snap the two windows side by side. Each section below links its own diagram.
DHCP in one minute
A client with no address can't send an ordinary packet to a server it doesn't know, so DHCP starts with broadcasts. The client sends from 0.0.0.0 to 255.255.255.255, the limited broadcast address that reaches every device on the local network. Clients listen on UDP port 68 and servers on UDP port 67.
The client then moves through a small set of states, defined in RFC 2131 section 4.4:
Every lease carries three timers, all counted from the moment the server grants it:
| Timer | Default | What the client does when it expires |
|---|---|---|
| T1 (renewal time) | 50% of the lease | Unicasts a Request to the server that granted the lease |
| T2 (rebinding time) | 87.5% of the lease | Broadcasts a Request to any server |
| Lease time | 100% | Stops using the address and starts over with a Discover |
The defaults come from RFC 2131 section 4.4.5. A server can send other values, as the third capture shows.
Four fields in the fixed DHCP header carry most of the story. Their names come from BOOTP, the older protocol DHCP extends:
ciaddr(client IP address): filled in only when the client already owns the address, for example when renewing or releasing it.yiaddr("your" IP address): the address the server is offering or confirming.giaddr(gateway IP address): set by a relay agent to its own address on the client's network.hops: the number of relay agents the message has crossed.
Capture 1: DORA on one LAN, then a release
The client, a host named H1, and the DHCP server at 10.1.10.1 share one Ethernet segment. The capture has seven frames: the four DORA messages and three copies of a Release.
What does each DORA message do?
Frame 1: Discover. H1 broadcasts from 0.0.0.0, port 68 to 67, with transaction ID 0x26b9. The client picks this random number, and every reply carries it back, so the client can match answers to its question. H1 also sets the broadcast flag. That asks the server to broadcast its replies, because a client without a configured address may not accept a packet sent to an address it doesn't have yet.
Frame 2: Offer. 0.14 ms later the server offers yiaddr 10.1.10.13, with everything else the client needs: mask 255.255.255.0, router 10.1.10.1, DNS servers 8.8.8.8 and 8.8.4.4 (the resolvers that will do the client's name lookups), and a one-day lease. T1 is 12 hours and T2 is 21 hours, exactly the 50% and 87.5% defaults. The Server Identifier option, 10.1.10.1, names the server. Nothing is reserved for certain yet; this is only an offer.
Frame 3: Request. H1 accepts by repeating two values from the Offer: the Requested IP Address (10.1.10.13) and the Server Identifier (10.1.10.1).
Frame 4: ACK. The server commits the lease, with the same options as the Offer. H1 can now configure its interface. The four messages took about 0.7 ms in total.
Why is the DHCP Request broadcast?
H1 knows exactly which server it is answering, yet frame 3 still goes to 255.255.255.255. That is deliberate. A network can have several DHCP servers, and a client may receive several Offers. Broadcasting the Request lets every server see it. The server named in the Server Identifier goes on to commit the lease, and the others learn their offers were declined and can release the addresses they set aside (RFC 2131 section 3.1).
What does a DHCP Release look like?
About 30 seconds after the ACK, H1 gives the address back. Now that it owns 10.1.10.13, it sends from that address straight to the server by unicast. ciaddr holds the address being returned, and the Server Identifier names the server that granted it.
H1 sends the Release three times: at 30.0 s, then 0.4 s later, then 2 s after that. RFC 2131 defines no reply to a Release (section 4.4.6), so a client can never confirm one arrived, and the server here answers none of them. Sending extra copies is this client's way of covering a lost packet. If all were lost, nothing would break: the address would stay reserved until the lease expired.
Capture 2: through a relay agent over a tunnel
Broadcasts stop at a router. A company with hundreds of branch LANs doesn't want a DHCP server on each one, so the router on each LAN acts as a relay agent: it picks up the client's broadcasts and forwards them to a central server by unicast. On Cisco IOS this is the ip helper-address command.
In this capture the client is a router named R4 on a branch LAN, 10.2.4.0/24. The branch router (the "spoke") relays to a DHCP server on the headquarters router (the "hub"). The two routers are joined by a DMVPN tunnel, a GRE tunnel across the internet, so the relayed messages travel inside GRE packets between 203.0.113.2 and 203.0.113.1. The capture shows both legs: the client's LAN and the tunnel.
What does a DHCP relay agent change?
Compare frame 1, the Discover on the client's LAN, with frame 2, the relayed copy on the tunnel. The client's own fields are untouched: same transaction ID 0x1aa6, same broadcast flag, same host name R4. The relay changes two header fields, as RFC 1542 section 4.1.1 requires:
giaddrgoes from empty to10.2.4.2, the relay's own address on R4's LAN.hopsgoes from 0 to 1.
It also readdresses the packet. Frame 2 travels from 10.2.4.2 to the server at 10.0.0.1, as a unicast from UDP port 67 to 67. Relay agents use the server port on both ends.
Here is frame 2's full decode. The layers show the outer IP header between the tunnel endpoints, the GRE header, the inner IP and UDP headers, and the DHCP message with Hops: 1 and Relay agent IP address: 10.2.4.2:
frame : Frame 2: Packet, 371 bytes on wire (2968 bits), 371 bytes captured (2968 bits) on interface -, id 0
Interface id : 0 (-)
eth : Ethernet II, Src: aa:bb:cc:00:02:00, Dst: aa:bb:cc:00:01:00
Destination : aa:bb:cc:00:01:00
Source : aa:bb:cc:00:02:00
ip : Internet Protocol Version 4, Src: 203.0.113.2, Dst: 203.0.113.1
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
000. .... = Flags : 0x0
gre : Generic Routing Encapsulation (IP)
Flags and Version : 0x2000
ip : Internet Protocol Version 4, Src: 10.2.4.2, Dst: 10.0.0.1
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
000. .... = Flags : 0x0
udp : User Datagram Protocol, Src Port: 67, Dst Port: 67
Timestamps
dhcp : Dynamic Host Configuration Protocol (Discover)
Bootp flags : 0x8000, Broadcast flag (Broadcast)
Option : (53) DHCP Message Type (Discover)
Option : (57) Maximum DHCP Message Size
Option : (61) Client identifier
Option : (12) Host Name
Option : (55) Parameter Request List
Option : (60) Vendor class identifier
Option : (255) End
How does the server know which address to hand out?
From giaddr. A central server holds a separate address pool for every branch, and the relay's address tells it which LAN the client is on (RFC 2131 section 4.3.1). Here giaddr 10.2.4.2 selects the 10.2.4.0/24 pool. The Offer in frame 3 proposes 10.2.4.52, with the default router set to 10.2.4.2, the relay's LAN interface.
giaddr also tells the server where to send the reply. The Offer goes back to the relay, not the client, from UDP 67 to 67 (RFC 2131 section 4.1). The relay then delivers it in frame 4. Because R4 set the broadcast flag, the relay broadcasts the Offer onto the LAN.
One detail is easy to miss. The relay sent the Discover to 10.0.0.1, the hub's tunnel address. The Offer comes back from 192.168.100.1, and its Server Identifier says the same. The server identifies itself by its own address, not by the address the relay happened to use. R4 copies 192.168.100.1 into its Request in frame 5, never knowing a relay was involved.
The Request and the ACK, frames 5 to 8, take the same path. Seconds after the ACK, outside the diagram, R4 sends a gratuitous ARP for 10.2.4.52, announcing its new address on the LAN, and pings the hub through the tunnel. All five pings are answered.
Capture 3: renewing a lease at T1
A real lease lasts hours or days, so watching a renewal normally takes patience. This lab shortens it: the server grants a 60-second lease, with T1 at 30 seconds and T2 at 49 seconds. Two renewals fit into 75 seconds of capture.
The client is router R1. Router R2 relays to the DHCP server, router R3 at 192.168.23.3. The capture was taken on the link between R1 and R2, so the relay's leg to R3 isn't in it.
How is a renewal Request different?
Frames 2 to 6 are an ordinary DORA exchange through a relay, like capture 2. Then, 34 seconds after the ACK, R1 renews. RFC 2131 asks clients to add a little random variation to T1, so that many clients given leases at the same moment don't all renew at once; 34 seconds rather than exactly 30 is expected.
The renewal Request in frame 13 differs from the Request in frame 5 in every field that matters:
| Field | Frame 5 (getting a lease) | Frame 13 (renewing it) |
|---|---|---|
| IP source | 0.0.0.0 | 192.168.12.1 |
| IP destination | 255.255.255.255 | 192.168.23.3 (the server) |
| Broadcast flag | Set | Clear |
ciaddr | Empty | 192.168.12.1 |
Server Identifier option | 192.168.23.3 | Absent |
Requested IP Address option | 192.168.12.1 | Absent |
In the RENEWING state the client has a working address, so it talks to the server directly. ciaddr names the lease being extended, and RFC 2131 forbids the other two options in this state (Table 5 in section 4.4.1). The packet isn't relayed: R2 simply routes it, so giaddr stays empty.
The ACK in frame 14 proves the point. It comes from R3 with an IP TTL of 254, one less than the 255 R3 sent, because R2 forwarded it as an ordinary routed packet. The server grants another 60 seconds, and 33 seconds later frames 16 and 17 repeat the cycle.
What happens if the server doesn't answer?
The client keeps retrying by unicast until T2, 49 seconds into the lease here. Then it assumes its server is gone and enters REBINDING: it broadcasts the Request so that any server can extend the lease. If the lease runs out with no answer, the client must stop using the address and start again from a Discover. None of this happens in the capture, because R3 answers every renewal within a millisecond.
The two-second pause before the Offer
In capture 1 the Offer follows the Discover in 0.14 ms. In captures 2 and 3 it takes about 2 seconds, while the Request and ACK that follow are nearly instant.
RFC 2131 section 2.2 suggests why: a server should check that an address is free before offering it, for example by sending it an ICMP echo request (a ping). If something answers, the address is in use despite what the server's records say, and the server offers another one.
Capture 3 shows traces of that check, even though the server is two hops away. One millisecond after R1's Discover, R2 sends an ARP request asking which device has 192.168.12.1, the address that is about to be offered (frame 3). Nobody answers, because R1 doesn't have it yet. R2 would need that ARP only to deliver a packet to 192.168.12.1, which fits R3 pinging the address. Then, in frame 8, an echo request from R3 to 192.168.12.1 appears, just after R1 has taken the address and announced it with a gratuitous ARP. The capture doesn't show the server's side, so this is a reading of the evidence rather than proof, but it matches the RFC's probe. Capture 1's server, which offers in 0.14 ms, evidently doesn't run the check.
Frequently asked questions
What does DORA stand for in DHCP? Discover, Offer, Request, Acknowledge: the four messages a client and server exchange to grant a new lease. Capture 1 shows all four in 0.7 ms.
Which ports does DHCP use? UDP port 67 for servers and relay agents, and UDP port 68 for clients. Relay-to-server traffic uses port 67 on both ends.
Why does a DHCP client set the broadcast flag? To ask the server, or the relay, to broadcast replies, because the client can't yet receive packets sent to an address it doesn't have. All three clients here set it during DORA.
What is giaddr? The relay agent's address on the client's network. The server uses it to pick the address pool and to know where to send its reply.
Does a DHCP renewal go through the relay agent? No. A renewing client unicasts straight to the server, as capture 3 shows. Only broadcasts need relaying.
Takeaways
- DHCP starts with broadcasts because the client has no address. The Discover, and the Request too, go to
255.255.255.255from0.0.0.0. - The Request is broadcast on purpose, so every server that made an offer learns which one was chosen.
- A relay agent changes two fields,
giaddrandhops.giaddrdecides both the address pool and where the reply goes. - Renewals skip the relay. At T1 the client unicasts to its server with
ciaddrset, and leaves out theServer IdentifierandRequested IP Addressoptions. - Nothing confirms a Release. That's why the client in capture 1 sends it three times.