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:

  1. 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.
  2. A relay agent carries the same exchange to a server on another network, across a VPN tunnel.
  3. 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:

stateDiagram-v2 accTitle: DHCP client state machine accDescr: The client starts in INIT and broadcasts a Discover, entering SELECTING. On receiving an Offer it sends a Request and enters REQUESTING. An ACK moves it to BOUND, where it holds the lease. At timer T1 it enters RENEWING and unicasts a Request to its server. An ACK returns it to BOUND. If T2 passes with no answer it enters REBINDING and broadcasts the Request. Sending a Release returns it to INIT. [*] --> INIT INIT --> SELECTING: send Discover SELECTING --> REQUESTING: Offer received, send Request REQUESTING --> BOUND: ACK received BOUND --> RENEWING: T1 expires, unicast Request RENEWING --> BOUND: ACK received RENEWING --> REBINDING: T2 expires, broadcast Request REBINDING --> BOUND: ACK received BOUND --> INIT: send Release
The DHCP client states these captures pass through. REBINDING is shown for completeness. None of the captures reaches it, because the server always answers the renewal in time.

Every lease carries three timers, all counted from the moment the server grants it:

TimerDefaultWhat the client does when it expires
T1 (renewal time)50% of the leaseUnicasts a Request to the server that granted the lease
T2 (rebinding time)87.5% of the leaseBroadcasts a Request to any server
Lease time100%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:

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.

sequenceDiagram accTitle: DHCP DORA exchange and release on one LAN accDescr: Client H1 broadcasts a Discover. The server broadcasts an Offer of 10.1.10.13. H1 broadcasts a Request naming that address and server. The server broadcasts an ACK. About 30 seconds later H1 unicasts a Release to the server three times, and the server sends no reply. participant C as H1 (client) participant S as DHCP server C->>S: [1] Discover (broadcast) S->>C: [2] Offer 10.1.10.13 (broadcast) C->>S: [3] Request 10.1.10.13 from 10.1.10.1 (broadcast) S->>C: [4] ACK, lease 1 day (broadcast) C->>S: [5] [6] [7] Release 10.1.10.13 (unicast, no reply)
Capture 1 at a glance. Every DORA message is broadcast. Frame numbers are in brackets.

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.

sequenceDiagram accTitle: DHCP exchange through a relay agent accDescr: Client R4 broadcasts a Discover. The spoke router, acting as relay agent, forwards it by unicast to the hub's DHCP server with giaddr 10.2.4.2. About two seconds later the server returns an Offer of 10.2.4.52 to the relay, which broadcasts it to R4. The Request and the ACK follow the same path. participant C as R4 (client) participant R as Spoke (relay agent) participant S as Hub (DHCP server) C->>R: [1] Discover (broadcast) R->>S: [2] Discover, giaddr 10.2.4.2, hops 1 S->>R: [3] Offer 10.2.4.52 R->>C: [4] Offer (broadcast) C->>R: [5] Request (broadcast) R->>S: [6] Request, giaddr 10.2.4.2 S->>R: [7] ACK R->>C: [8] ACK (broadcast)
Capture 2 at a glance. The relay turns each broadcast into a unicast to the server, and delivers each reply back onto the client's LAN. Frame numbers are in brackets.

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:

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:

🔍 [00002] Frame 2 DHCP Discover 2020-08-12T14:45:07.238447Z 🔗 Spoke (relay agent) → 🗄 Hub (DHCP server)
frame : Frame 2: Packet, 371 bytes on wire (2968 bits), 371 bytes captured (2968 bits) on interface -, id 0
Section number : 1
Interface id : 0 (-)
Interface name : -
Encapsulation type : Ethernet (1)
Arrival Time : Aug 12, 2020 20:15:07.238447000 India Standard Time
UTC Arrival Time : Aug 12, 2020 14:45:07.238447000 UTC
Epoch Arrival Time : 1597243507.238447000
Time shift for this packet : 0.000000000 seconds
Time delta from previous captured frame : 605.000 microseconds
Time delta from previous displayed frame : 605.000 microseconds
Time since reference or first frame : 605.000 microseconds
Frame Number : 2
Frame Length : 371 bytes (2968 bits)
Capture Length : 371 bytes (2968 bits)
Frame is marked : False
Frame is ignored : False
Protocols in frame : eth:ethertype:ip:gre:ip:udp:dhcp
Character encoding : ASCII (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
Destination (resolved) : aa:bb:cc:00:01:00
Destination OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Address : aa:bb:cc:00:01:00
Address (resolved) : aa:bb:cc:00:01:00
Address OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Source : aa:bb:cc:00:02:00
Source (resolved) : aa:bb:cc:00:02:00
Source OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Address : aa:bb:cc:00:02:00
Address (resolved) : aa:bb:cc:00:02:00
Address OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Type : IPv4 (0x0800)
Stream index : 1
ip : Internet Protocol Version 4, Src: 203.0.113.2, Dst: 203.0.113.1
0100 .... = Version : 4
.... 0101 = Header Length : 20 bytes (5)
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
0000 00.. = Differentiated Services Codepoint : Default (0)
.... ..00 = Explicit Congestion Notification : Not ECN-Capable Transport (0)
Total Length : 357
Identification : 0x011f (287)
000. .... = Flags : 0x0
0... .... = Reserved bit : Not set
.0.. .... = Don't fragment : Not set
..0. .... = More fragments : Not set
...0 0000 0000 0000 = Fragment Offset : 0
Time to Live : 255
Protocol : Generic Routing Encapsulation (47)
Header Checksum : 0x4146 [validation disabled]
Header checksum status : Unverified
Source Address : 203.0.113.2
Source or Destination Address : 203.0.113.2
Source Host : 203.0.113.2
Source or Destination Host : 203.0.113.2
Destination Address : 203.0.113.1
Source or Destination Address : 203.0.113.1
Destination Host : 203.0.113.1
Source or Destination Host : 203.0.113.1
Stream index : 1
gre : Generic Routing Encapsulation (IP)
Flags and Version : 0x2000
0... .... .... .... = Checksum Bit : No
.0.. .... .... .... = Routing Bit : No
..1. .... .... .... = Key Bit : Yes
...0 .... .... .... = Sequence Number Bit : No
.... 0... .... .... = Strict Source Route Bit : No
.... .000 .... .... = Recursion control : 0
.... .... 0000 0... = Flags (Reserved) : 0
.... .... .... .000 = Version : GRE (0)
Protocol Type : IP (0x0800)
Key : 0x00000064
ip : Internet Protocol Version 4, Src: 10.2.4.2, Dst: 10.0.0.1
0100 .... = Version : 4
.... 0101 = Header Length : 20 bytes (5)
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
0000 00.. = Differentiated Services Codepoint : Default (0)
.... ..00 = Explicit Congestion Notification : Not ECN-Capable Transport (0)
Total Length : 329
Identification : 0x0007 (7)
000. .... = Flags : 0x0
0... .... = Reserved bit : Not set
.0.. .... = Don't fragment : Not set
..0. .... = More fragments : Not set
...0 0000 0000 0000 = Fragment Offset : 0
Time to Live : 255
Protocol : UDP (17)
Header Checksum : 0xa298 [validation disabled]
Header checksum status : Unverified
Source Address : 10.2.4.2
Source or Destination Address : 10.2.4.2
Source Host : 10.2.4.2
Source or Destination Host : 10.2.4.2
Destination Address : 10.0.0.1
Source or Destination Address : 10.0.0.1
Destination Host : 10.0.0.1
Source or Destination Host : 10.0.0.1
Stream index : 2
udp : User Datagram Protocol, Src Port: 67, Dst Port: 67
Source Port : 67
Destination Port : 67
Source or Destination Port : 67
Source or Destination Port : 67
Length : 309
Checksum : 0xd30e [unverified]
Checksum Status : Unverified
Stream index : 1
Stream Packet Number : 1
Timestamps
Time since first frame : 0.000000000 seconds
Time since previous frame : 0.000000000 seconds
UDP payload (301 bytes)
dhcp : Dynamic Host Configuration Protocol (Discover)
Message type : Boot Request (1)
Hardware type : Ethernet (0x01)
Hardware address length : 6
Hops : 1
Transaction ID : 0x00001aa6
Seconds elapsed : 0
Bootp flags : 0x8000, Broadcast flag (Broadcast)
1... .... .... .... = Broadcast flag : Broadcast
.000 0000 0000 0000 = Reserved flags : 0x0000
Client IP address : 0.0.0.0
Your (client) IP address : 0.0.0.0
Next server IP address : 0.0.0.0
Relay agent IP address : 10.2.4.2
Client MAC address : aa:bb:cc:00:04:20
Client hardware address padding : 00000000000000000000
Server host name not given
Boot file name not given
Magic cookie : DHCP
Option : (53) DHCP Message Type (Discover)
Length : 1
Value : 01
DHCP : Discover (1)
Option : (57) Maximum DHCP Message Size
Length : 2
Value : 04b0
Maximum DHCP Message Size : 1200
Option : (61) Client identifier
Length : 27
Value : 00636973636f2d616162622e636330302e303432302d4574302f32
Type : 0
Client Identifier : cisco-aabb.cc00.0420-Et0/2
Option : (12) Host Name
Length : 2
Value : 5234
Host Name : R4
Option : (55) Parameter Request List
Length : 8
Value : 01060f2c0321962b
Parameter Request List Item : (1) Subnet Mask
Parameter Request List Item : (6) Domain Name Server
Parameter Request List Item : (15) Domain Name
Parameter Request List Item : (44) NetBIOS over TCP/IP Name Server
Parameter Request List Item : (3) Router
Parameter Request List Item : (33) Static Route
Parameter Request List Item : (150) TFTP Server Address
Parameter Request List Item : (43) Vendor-Specific Information
Option : (60) Vendor class identifier
Length : 8
Value : 636973636f706e70
Vendor class identifier : ciscopnp
Option : (255) End
Option End : 255
Rendered from a Wireshark PCAP by VisualEther.

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.

sequenceDiagram accTitle: DHCP lease and two renewals accDescr: Client R1 broadcasts a Discover and receives an Offer of 192.168.12.1 through relay R2, with a 60 second lease. It broadcasts a Request and receives an ACK. About 34 seconds later it unicasts a Request directly to the server R3, which answers with an ACK. About 33 seconds after that the renewal repeats. participant C as R1 (client) participant R as R2 (relay agent) participant S as R3 (DHCP server) C->>R: [2] Discover (broadcast) R->>C: [4] Offer 192.168.12.1, lease 60 s C->>R: [5] Request (broadcast) R->>C: [6] ACK, lease 60 s C->>S: [13] Request, ciaddr 192.168.12.1 (unicast) S->>C: [14] ACK, lease 60 s C->>S: [16] Request (unicast) S->>C: [17] ACK, lease 60 s
Capture 3 at a glance. The first lease goes through the relay. Each renewal goes straight from client to server. Frame numbers are in brackets.

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:

FieldFrame 5 (getting a lease)Frame 13 (renewing it)
IP source0.0.0.0192.168.12.1
IP destination255.255.255.255192.168.23.3 (the server)
Broadcast flagSetClear
ciaddrEmpty192.168.12.1
Server Identifier option192.168.23.3Absent
Requested IP Address option192.168.12.1Absent

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

  1. DHCP starts with broadcasts because the client has no address. The Discover, and the Request too, go to 255.255.255.255 from 0.0.0.0.
  2. The Request is broadcast on purpose, so every server that made an offer learns which one was chosen.
  3. A relay agent changes two fields, giaddr and hops. giaddr decides both the address pool and where the reply goes.
  4. Renewals skip the relay. At T1 the client unicasts to its server with ciaddr set, and leaves out the Server Identifier and Requested IP Address options.
  5. Nothing confirms a Release. That's why the client in capture 1 sends it three times.