15. DHCP: Getting an Address Without Asking a Human

How a laptop with no address, no router and no idea where it is ends up with all three, in four broadcast-friendly UDP messages, and what keeps the arrangement going for days

Imagine walking into a hotel lobby with nothing: no booking, no room number, no idea where the front desk is. So you call out to the room in general: "Hello? I need a room!" Somebody behind a counter calls back: "Room 10 is free. Breakfast is on the ground floor, the lift is on your left, and checkout is nine tomorrow morning." Before you take it, you announce loudly enough for every desk in the lobby to hear, "I'll take room 10, from that desk", so any other receptionist who was about to offer you something knows not to bother. The receptionist hands over a key card that will open room 10 until nine tomorrow.

The interesting part is what happens next. Halfway through your stay, you stop by the desk and ask to extend, and the card is reprogrammed for another day. If your receptionist has gone home, you ask any member of staff. If nobody extends it at all, at nine o'clock the card simply stops working, and you're back in the lobby with your bags, calling out again.

That is DHCP, the Dynamic Host Configuration Protocol, almost exactly. A machine that has just joined a network has no IP address and doesn't know the router, the DNS server or even which subnet it's on. It shouts on the local link, a server answers with an address and everything else it needs to know, and the address comes as a lease that has to be renewed before it runs out. Every laptop, phone, TV and light bulb that has ever "just connected" to a network did this first.

This page follows our laptop through that conversation byte by byte, then watches its lease renew, struggle and expire, and finally looks at what happens on the server, through relays, under attack and in IPv6.

Why Not Just Type It In?

Every host on an IPv4 network needs at least four pieces of configuration before it can do anything useful, all of which we've met in this series:

  • an address and mask: 192.168.10.10/24 for our laptop on VLAN 10 (IPv4 Addressing);
  • a default gateway: 192.168.10.1, R1 (Routing Basics);
  • a DNS server, to turn names into addresses: R1 again, which runs a forwarder (UDP);
  • usually a domain name to append to short names, so that nas means nas.home.arpa.

You can type all of these in by hand, and for a router or a server you often should. But picture doing it for every device in a building. Somebody has to keep a spreadsheet of which addresses are taken; two people pick the same one and both machines break in confusing ways (the ARP article showed what a duplicate looks like); a laptop carried to another floor, or another office, has the wrong subnet entirely; and when the DNS server moves, every machine has to be visited again. Static configuration doesn't fail loudly. It rots.

RARP, BOOTP, DHCP

The fix arrived in three steps, each driven by the machines of its day.

RARP (RFC 903, June 1984), from four researchers at Stanford, was built for diskless workstations, which had no disk to store an address on. A machine broadcast "here's my MAC, what's my IP?" in an ARP-like packet straight over Ethernet (EtherType 0x8035), and a RARP server on the same segment looked the MAC up in a table. It worked, but it answered exactly one question: the IP address. Not the mask, not the router. And because it ran below IP, it couldn't cross a router, so every segment needed its own RARP server.

BOOTP, the Bootstrap Protocol (RFC 951, September 1985, by Bill Croft and John Gilmore), fixed both problems by running over UDP: a client with no address broadcast a request, and a BOOTP server answered with an address, the server to boot from and a boot file name. Being IP, it could be relayed across routers. A 64-byte "vendor" area at the end carried extra settings, and RFC 1048 (1988) gave it a structure: a four-byte magic cookie, 63 82 53 63, followed by tagged options for the mask, the routers, DNS servers and so on. That cookie is still at the same offset in every DHCP message today.

BOOTP's weakness was that the server's table was still written by hand: one line per MAC, an address for each, forever. DHCP (RFC 1531, October 1993, by Ralph Droms, revised as RFC 2131 and its options document RFC 2132 in March 1997) kept BOOTP's packet format and ports, so that BOOTP relays and even BOOTP clients kept working, and added the idea that changed everything: addresses come from a pool, on a lease with a time limit. A server can now hand an address to a machine it has never seen, and get it back when the machine goes away. RFC 2131 names three ways a server can allocate:

  • Dynamic: from the pool, for a limited time. This is what almost everything uses.
  • Automatic: from the pool, permanently.
  • Manual: the administrator chooses the address for a given client, and DHCP just delivers it. Today we call these reservations.

DHCPv4 has barely changed since 1997. New options keep being added (there are well over a hundred), but the four-message exchange and the lease timers are exactly as RFC 2131 wrote them.

The Four-Message Exchange

Our laptop has just been plugged into port 1 of switch A, an access port in VLAN 10. Its link comes up. It has a MAC address, 02:00:00:aa:bb:01, and nothing else. The exchange that follows is usually remembered by its initials, DORA:

Laptop …aa:bb:01 · no IP yet R1 · DHCP server 192.168.10.1 · …cc:dd:02 1 · DHCPDISCOVER 0.0.0.0:68 → 255.255.255.255:67 · broadcast 2 · DHCPOFFER "192.168.10.10?" 192.168.10.1:67 → 192.168.10.10:68 · to …aa:bb:01 3 · DHCPREQUEST "I'll take .10 from .1" 0.0.0.0:68 → 255.255.255.255:67 · broadcast 4 · DHCPACK "yours for 24 hours" 192.168.10.1:67 → 192.168.10.10:68 · to …aa:bb:01 ARP-probe 192.168.10.10, then configure /24, gateway .1, DNS .1, domain home.arpa orange = broadcast
  1. Discover: "is there a DHCP server out there?"

    The laptop broadcasts a DHCPDISCOVER to every machine on the link. It includes its MAC address, a random transaction ID to match answers to this question, and a list of the settings it would like.

  2. Offer: "you could have 192.168.10.10"

    Every DHCP server that hears it and has a free address may answer with a DHCPOFFER: an address, a lease time, and the settings that go with it. On our network that's just R1.

  3. Request: "I'll take it, from you"

    The laptop picks one offer (usually the first) and broadcasts a DHCPREQUEST naming both the address and the server that offered it.

  4. Acknowledge: "it's yours until 09:00 tomorrow"

    The chosen server records the lease and confirms it with a DHCPACK. The laptop checks nobody else is already using the address, then configures its interface and its default route.

Two round trips, four small UDP datagrams, and on a home network the whole exchange takes a few milliseconds. The odd-looking details are all in how those datagrams are addressed.

Talking without an address

The laptop has no IP address to send from, so it uses 0.0.0.0, which as a source means "this host, on this network": I don't know my address yet (IPv4 Addressing lists it). It doesn't know where the server is, so it sends to 255.255.255.255, the limited broadcast, "everyone on this link", which routers never forward. In the Ethernet header that becomes ff:ff:ff:ff:ff:ff, so the switch floods the frame to every port in VLAN 10, and only VLAN 10 (the VLANs article promised this would matter).

It uses UDP because TCP can't do this at all: TCP needs a handshake with one known peer, and the laptop knows nobody. UDP will happily carry a datagram to "whoever is out there", as the UDP article put it.

Two fixed ports, 67 and 68

DHCP servers listen on UDP port 67 and clients on port 68. The client's port is fixed too, which is unusual: most clients use a random ephemeral port. RFC 951 explains why. A server may have to broadcast its reply, because the client has no address to unicast to. If the client had picked a random port, say 41853, that broadcast would land on every machine in the network, and any of them that happened to have a program on port 41853 would get a baffling packet. With a reserved client port, nobody else is listening, and the other hosts' kernels throw the broadcast away. That's the "UDP 68 · DHCP client" socket in the laptop's demultiplexing diagram: an unconnected socket that accepts DHCP replies from anyone.

Unicast or broadcast replies? The broadcast flag

How can R1 send the OFFER to 192.168.10.10 when the laptop hasn't accepted that address yet? Normally R1 would ARP for 192.168.10.10 first, and the laptop wouldn't answer, because it doesn't own the address. So the server skips ARP: it already knows the client's MAC from the request, writes the Ethernet frame straight to …aa:bb:01 with the offered address as the IP destination, and the laptop's DHCP client, which reads raw frames from the network card rather than relying on a configured IP stack, picks it up.

Not every client can receive an IP packet addressed to an address it doesn't have yet. RFC 2131 gives those clients a way to say so: the top bit of the 16-bit flags field, the broadcast flag (80 00 on the wire). If it's set, the server sends its OFFER and ACK to 255.255.255.255 and ff:ff:ff:ff:ff:ff instead. Our Linux laptop leaves it clear, as RFC 2131 asks of clients that can cope. Windows Vista famously shipped with it set, and some home routers of the day couldn't handle the flag, which left Vista machines with no address (Microsoft's KB 928233 told people how to switch it off).

Why the REQUEST is broadcast too

By step 3 the laptop knows R1's address, so why broadcast again? Because there might have been other servers that also made offers and are holding addresses aside for it. The REQUEST's server identifier option names the winner, 192.168.10.1, and broadcasting it lets every server hear the result at once: R1 commits the lease, and the others release whatever they offered. It's the hotel guest announcing to the whole lobby which desk they're going with.

The Message Format

Every DHCP message, from all four steps and every other kind, has the same layout, inherited unchanged from BOOTP: a 236-byte fixed header, the magic cookie, and then a variable list of options.

0 4 8 12 16 20 24 28 44 108 236 240 op 01 htype 01 hlen 06 hops 00 xid (4) · transaction ID · 3c 41 e9 a7 secs (2) · 00 00 flags (2) · B = broadcast · 00 00 ciaddr · client's current address, if it has one yiaddr · "your" address, filled in by the server siaddr · next server, for network boot giaddr · relay agent's address chaddr (16) · 02 00 00 aa bb 01 + 10 zero bytes sname (64) · server host name · usually all zero file (128) · boot file name · usually all zero magic cookie (4) · 63 82 53 63 = 99.130.83.99 options · type, length, value … ending with ff Left: byte offsets within the DHCP message (add 28 for the offset in the IP packet).
Bytes Field Meaning
0 op 1 BOOTREQUEST (client to server) or 2 BOOTREPLY
1, 2 htype, hlen Hardware type 1 (Ethernet) and address length 6
3 hops Clients send 0; each relay adds 1
4–7 xid Random transaction ID; replies copy it
8–9 secs Seconds since the client started trying
10–11 flags Top bit: the broadcast flag. The other 15 are zero
12–15 ciaddr The client's address, only when it already has one
16–19 yiaddr "Your" address: what the server is giving
20–23 siaddr Next server, for network boot
24–27 giaddr The relay agent that forwarded this, if any
28–43 chaddr Client hardware address, padded to 16 bytes
44–235 sname, file Boot server name and boot file, 64 + 128 bytes
236–239 cookie 63 82 53 63: options follow

A few of those deserve a closer look:

  • Four address fields, four different jobs. ciaddr is filled in by a client that already owns an address and is renewing it; yiaddr is how the server says "this is yours". The two are separate because they mean different things at different moments: in a renewal ACK, both hold 192.168.10.10. siaddr and giaddr come from BOOTP's network-booting and relaying days, and giaddr is still central to relays.
  • chaddr is 16 bytes because BOOTP was designed for every kind of link, not just Ethernet. With hlen = 6, only the first six are used.
  • sname and file told a diskless BOOTP client where to fetch its operating system, by TFTP from siaddr. Network booting (PXE) still uses them. Everyone else sends 192 bytes of zeros, which is why DHCP messages are mostly empty. When a server runs out of room for options it may even "overload" these two fields with more options, flagged by option 52.
  • xid is how the client recognises its answer. Replies may be broadcast, so the laptop ignores any OFFER whose xid doesn't match its latest DISCOVER.

Options: type, length, value

After the cookie comes a list of options, each written as one code byte, one length byte, and that many bytes of value. Two codes are special and have no length: 0 is padding, and 255 marks the end. An option's value is at most 255 bytes; longer values are split across repeated copies of the option, which the receiver glues back together.

The one option every DHCP message must carry is 53, the message type. It's what turns a generic BOOTP request into a DISCOVER or a REQUEST. These are the options our laptop's exchange uses, plus two more we'll meet later:

Code Option In our exchange
53 DHCP message type 1 DISCOVER, 2 OFFER, 3 REQUEST, 4 DECLINE, 5 ACK, 6 NAK, 7 RELEASE, 8 INFORM
61 Client identifier Type 01 (Ethernet) + MAC
12 Host name "laptop"
55 Parameter request list Please send 1, 3, 6 and 15
50 Requested IP address 192.168.10.10, in the REQUEST
54 Server identifier 192.168.10.1: which server is speaking, or was chosen
51 Lease time 86400 s, one day
58, 59 Renewal (T1) and rebinding (T2) time 43200 s and 75600 s
1 Subnet mask 255.255.255.0
3 Router 192.168.10.1
6 DNS servers 192.168.10.1
15 Domain name "home.arpa"
56 Message Free text, e.g. why a NAK was sent
82 Relay agent information Added by relays
255 End No length byte

The domain is home.arpa, which RFC 8375 (2018) reserved for exactly this, home networks, so our names can't collide with anything on the public Internet. Every time option values are IP addresses they're four raw bytes, and every time they're times they're 32-bit counts of seconds, so a lease of 00 01 51 80 is 86,400 seconds. A value of ff ff ff ff means an infinite lease.

The client identifier (61) is worth a moment. By default a server identifies a client by its MAC address in chaddr, but a client can supply its own identity instead, and if it does, the server must key the lease on that. Ours sends the simplest form, type 01 (Ethernet) followed by the MAC, which amounts to the same thing. Some clients send something that survives a change of network card instead: RFC 4361 defines identifiers built from a DUID, the stable ID that DHCPv6 uses, which we'll meet later. Since RFC 6842 (2013), a server must echo a client identifier back in its replies, which is why R1's OFFER and ACK carry option 61 too.

DORA, Byte by Byte

Here is the laptop's DISCOVER as it leaves the network card, without the Ethernet header (from …aa:bb:01 to ff:ff:ff:ff:ff:ff, EtherType 0800). Every byte and both checksums are real, computed for these exact bytes. The line marked * is hexdump shorthand: "the lines from here on repeat the one above", here sixteen lines of zeros through sname and file.

Hex dump: the DHCPDISCOVER, a 328-byte IPv4 packet

0000  45 00 01 48 00 00 00 00 40 11 79 a6 00 00 00 00  [email protected].....
0010  ff ff ff ff 00 44 00 43 01 34 cb 35 01 01 06 00  .....D.C.4.5....
0020  3c 41 e9 a7 00 00 00 00 00 00 00 00 00 00 00 00  <A..............
0030  00 00 00 00 00 00 00 00 02 00 00 aa bb 01 00 00  ................
0040  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
*
0100  00 00 00 00 00 00 00 00 63 82 53 63 35 01 01 3d  ........c.Sc5..=
0110  07 01 02 00 00 aa bb 01 0c 06 6c 61 70 74 6f 70  ..........laptop
0120  37 04 01 03 06 0f ff 00 00 00 00 00 00 00 00 00  7...............
0130  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0140  00 00 00 00 00 00 00 00                          ........

 IPv4  0–19 ·  UDP  20–27 ·  fixed fields  28–263 ·  cookie  264–267 ·  options  268–294 · padding 295–327

Read it as R1's kernel and then its DHCP server do:

  1. Offset 0x00: IPv4

    45: version 4, 20-byte header. Total length 01 48 = 328. Identification 00 00, and no Don't Fragment flag: the client builds this packet by hand, in its raw socket. TTL 40 = 64. Protocol 11 = UDP. Header checksum 79 a6. Source 00 00 00 00, destination ff ff ff ff.

  2. Offset 0x14: UDP

    Source port 00 44 = 68, destination 00 43 = 67. Length 01 34 = 308, which is 328 − 20. Checksum cb 35, worked out below. R1's kernel hands the 300 bytes after this to the socket on port 67.

  3. Offset 0x1c: the fixed fields

    01 01 06 00: a BOOTREQUEST, Ethernet, 6-byte addresses, no relays. Then xid = 3c 41 e9 a7, secs = 0, and flags = 00 00: the broadcast flag is clear. All four address fields are zero. At 0x38, chaddr starts with the laptop's MAC, 02 00 00 aa bb 01, followed by ten zero bytes, and then sname and file: 192 more zeros, all the way to 0x107.

  4. Offset 0x108: the cookie

    63 82 53 63, the same four bytes RFC 1048 chose in 1988. A server that doesn't see them knows what follows isn't DHCP options.

  5. Offset 0x10c: the options

    35 01 01: option 53, length 1, DISCOVER. 3d 07 01 02 00 00 aa bb 01: option 61, the client identifier. 0c 06 and six ASCII bytes: option 12, host name laptop. 37 04 01 03 06 0f: option 55, asking for the mask, router, DNS servers and domain name. Then ff, the end, at 0x126.

  6. Offset 0x127: padding

    Thirty-three zero bytes (option 0, pad) bring the DHCP message up to exactly 300 bytes. That's the minimum BOOTP message size, and RFC 1542 tells relays to check for it. Most clients and servers pad to 300 so that old relay agents never discard them.

So 27 bytes of options carry everything the laptop has to say, inside a 300-byte message, inside a 328-byte packet. DHCP was not designed to be thrifty.

The checksum over an address you don't have

The UDP checksum is computed exactly as in the UDP article, over a pseudo-header, the UDP header and the data. What's unusual is the pseudo-header: it vouches for a source address of 0.0.0.0 and a destination of 255.255.255.255.

The six pseudo-header words: 0000+0000+ffff+ffff+0011+0134=20143\texttt{0000} + \texttt{0000} + \texttt{ffff} + \texttt{ffff} + \texttt{0011} + \texttt{0134} = \texttt{20143}.

The UDP header (with its checksum as zero) and the 300 bytes of DHCP data sum to 6337f\texttt{6337f}. The total is 834c2\texttt{834c2}. Fold the carry: 34c2+8=34ca\texttt{34c2} + \texttt{8} = \texttt{34ca}. Flip every bit: ¬ 34ca=cb35\lnot\,\texttt{34ca} = \texttt{cb35}.

The IPv4 header checksum works the same way over the header's ten words. Only five are non-zero, 4500, 0148, 4011, ffff and ffff, and they sum to 28657, which folds to 8659; its complement is 79a6. Both values appear in the dump.

The OFFER

R1 picks an address (how, we'll see in the server side) and replies. Its kernel builds the IP header this time, so Don't Fragment is set:

Hex dump: the DHCPOFFER, 334 bytes

0000  45 00 01 4e 00 00 40 00 40 11 a4 43 c0 a8 0a 01  E..N..@[email protected]....
0010  c0 a8 0a 0a 00 43 00 44 01 3a ae 20 02 01 06 00  .....C.D.:. ....
0020  3c 41 e9 a7 00 00 00 00 00 00 00 00 c0 a8 0a 0a  <A..............
0030  00 00 00 00 00 00 00 00 02 00 00 aa bb 01 00 00  ................
0040  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
*
0100  00 00 00 00 00 00 00 00 63 82 53 63 35 01 02 3d  ........c.Sc5..=
0110  07 01 02 00 00 aa bb 01 36 04 c0 a8 0a 01 33 04  ........6.....3.
0120  00 01 51 80 3a 04 00 00 a8 c0 3b 04 00 01 27 50  ..Q.:.....;...'P
0130  01 04 ff ff ff 00 03 04 c0 a8 0a 01 06 04 c0 a8  ................
0140  0a 01 0f 09 68 6f 6d 65 2e 61 72 70 61 ff        ....home.arpa.
  • IP and UDP. From c0 a8 0a 01 (192.168.10.1) to c0 a8 0a 0a (192.168.10.10), port 67 to 68. IP checksum a4 43, UDP length 314, UDP checksum ae 20.
  • Fixed fields. op is 02, a reply. The xid is the laptop's, 3c 41 e9 a7. At 0x2c, yiaddr = c0 a8 0a 0a: the offer itself. chaddr is copied from the request.
  • Options. Message type 02, OFFER. The client identifier, echoed. Server identifier 36 04 c0 a8 0a 01. Lease time 33 04 00 01 51 80 = 86,400 s. T1 3a 04 00 00 a8 c0 = 43,200 s and T2 3b 04 00 01 27 50 = 75,600 s. Then the four settings the laptop asked for: mask, router, DNS server, and 0f 09 + home.arpa. Then ff.

The options run to 66 bytes, so this message is 306 bytes long and needs no padding.

The REQUEST and the ACK

The laptop's REQUEST is its DISCOVER again with message type 03 and two more options: 32 04 c0 a8 0a 0a, the requested IP address (50), and 36 04 c0 a8 0a 01, the server identifier (54) of the offer it's accepting. The xid stays the same, and ciaddr stays zero: the laptop doesn't own anything yet.

Hex dump: the DHCPREQUEST, 328 bytes

0000  45 00 01 48 00 00 00 00 40 11 79 a6 00 00 00 00  [email protected].....
0010  ff ff ff ff 00 44 00 43 01 34 cb d0 01 01 06 00  .....D.C.4......
0020  3c 41 e9 a7 00 00 00 00 00 00 00 00 00 00 00 00  <A..............
0030  00 00 00 00 00 00 00 00 02 00 00 aa bb 01 00 00  ................
0040  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
*
0100  00 00 00 00 00 00 00 00 63 82 53 63 35 01 03 3d  ........c.Sc5..=
0110  07 01 02 00 00 aa bb 01 32 04 c0 a8 0a 0a 36 04  ........2.....6.
0120  c0 a8 0a 01 0c 06 6c 61 70 74 6f 70 37 04 01 03  ......laptop7...
0130  06 0f ff 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0140  00 00 00 00 00 00 00 00                          ........

R1's ACK is byte-for-byte its OFFER with the message type changed from 02 to 05. That's exactly what RFC 2131 asks: the ACK shouldn't contradict the offer the client accepted. One changed byte moves the UDP checksum from ae 20 to ab 20. The message-type byte starts a 16-bit word, 023d in the OFFER and 053d in the ACK, which is 0300 bigger, so the checksum is 0300 smaller.

Hex dump: the DHCPACK, 334 bytes

0000  45 00 01 4e 00 00 40 00 40 11 a4 43 c0 a8 0a 01  E..N..@[email protected]....
0010  c0 a8 0a 0a 00 43 00 44 01 3a ab 20 02 01 06 00  .....C.D.:. ....
0020  3c 41 e9 a7 00 00 00 00 00 00 00 00 c0 a8 0a 0a  <A..............
0030  00 00 00 00 00 00 00 00 02 00 00 aa bb 01 00 00  ................
0040  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
*
0100  00 00 00 00 00 00 00 00 63 82 53 63 35 01 05 3d  ........c.Sc5..=
0110  07 01 02 00 00 aa bb 01 36 04 c0 a8 0a 01 33 04  ........6.....3.
0120  00 01 51 80 3a 04 00 00 a8 c0 3b 04 00 01 27 50  ..Q.:.....;...'P
0130  01 04 ff ff ff 00 03 04 c0 a8 0a 01 06 04 c0 a8  ................
0140  0a 01 0f 09 68 6f 6d 65 2e 61 72 70 61 ff        ....home.arpa.
Message IP / UDP checksum Lengths (IP, UDP, DHCP)
DISCOVER 79a6 / cb35 328, 308, 300
OFFER a443 / ae20 334, 314, 306
REQUEST 79a6 / cbd0 328, 308, 300
ACK a443 / ab20 334, 314, 306

When the ACK arrives, the laptop has everything. It checks the address isn't already taken (more on that below), assigns 192.168.10.10/24 to eth0, adds the default route via 192.168.10.1, points its resolver at 192.168.10.1, and starts its timers. The Routing Basics article showed the result: a default route marked proto dhcp.

Build these messages yourself, or paste a capture to take it apart. Each preset is one of this article's messages, with the same bytes and checksums as above.

The fixed fields

op, htype and hlen follow from the message type and Ethernet; everything else is yours to change.

Options, in order

Addresses as dotted quads (lists separated by commas), times in seconds, option 61 as a MAC address or raw hex.

Delivery

On the wire

IPv4 and UDP headers

The 236 fixed bytes

Offsets are within the DHCP message; add 28 for the offset in the IP packet.

Cookie and options


      

The UDP checksum

Every 16-bit word, in order, with the running total. Runs of zero words add nothing, so they are folded into one row.

The IPv4 header checksum

Leases: Renew, Rebind, Expire

The laptop doesn't own 192.168.10.10. It has borrowed it for 86,400 seconds, and the clock started when it sent the REQUEST that got the ACK, at 09:00 this morning. Two more times, from options 58 and 59, decide what it does before the lease runs out:

T1=0.5×86400=43200 sT_1 = 0.5 \times 86400 = 43200\ \text{s}

T2=0.875×86400=75600 sT_2 = 0.875 \times 86400 = 75600\ \text{s}

That's 12 hours and 21 hours after the lease began.

Those are RFC 2131's defaults, so a server that leaves options 58 and 59 out gets the same behaviour. (RFC 2131 also suggests adding some random "fuzz" to them, so that a building full of machines switched on at 09:00 doesn't renew in one stampede at 21:00. dnsmasq, which R1 runs, does this on renewals; we keep the numbers round for clarity. The byte dumps above are idealised in the same way: a real dnsmasq reply would also carry a broadcast-address option, 28.)

BOUND RENEWING REBINDING ACK T1 · 50% T2 · 87.5% expiry 0 h 12 h 21 h 24 h use the address, no traffic REQUEST, unicast to R1 broadcast, any server An ACK at any point starts a fresh 24 hours from when that REQUEST was sent.

T1: renewing with the same server

At T1, 21:00, the laptop enters RENEWING and sends a DHCPREQUEST straight to the server that granted the lease, as an ordinary unicast from 192.168.10.10:68 to 192.168.10.1:67. It has an address now, so it uses it: ciaddr is 192.168.10.10, and the request carries no requested-IP or server-identifier option, which is how the server can tell a renewal from an acceptance. It also gets a fresh xid, 3c 41 e9 a8: one more than the last, a numbering scheme RFC 2131 suggests (pick a random xid at boot, then count up).

R1 answers with an ACK that has both ciaddr and yiaddr set to 192.168.10.10, and a new 24-hour lease that runs from the moment the renewal was sent. On a healthy network that's all that ever happens: one small unicast exchange every 12 hours, and the laptop keeps the same address for months.

T2: rebinding with anyone

If R1 doesn't answer, the laptop isn't in a hurry. It still has nine hours of lease left, so it retries, waiting half the remaining time until T2 each time, but never less than 60 seconds. If T2 arrives with no answer, the laptop concludes its server is gone and enters REBINDING: from now on it broadcasts its REQUEST, still from its own address, still with ciaddr set, so that any DHCP server that knows about this lease can extend it. That matters on networks with two servers sharing one lease database: if one dies, the other picks up the laptop at T2. Retries in REBINDING wait half the time remaining on the lease, again with a 60-second minimum.

Expiry

If the lease runs out with no ACK, the laptop must stop using the address immediately: RFC 2131 says it must halt network processing on it. It drops 192.168.10.10 and its default route and returns to INIT, broadcasting DISCOVERs as if it had just been switched on. Those are retransmitted with exponential backoff: after about 4 seconds, then 8, 16, 32 and 64, each randomised by up to a second either way so that a hundred machines don't retry in lockstep. Many clients give up after a minute or two and fall back to a self-assigned 169.254.x.x link-local address, the classic sign of "no DHCP server".

A day with the server down

Here's what that looks like if R1's DHCP service fails 20 hours after the laptop joined, eight hours after its first renewal at 12 hours, and comes back at 36 h 10 min. Times are hours, minutes and seconds since the laptop's first DISCOVER.

Time State: what happens
0:00:00 SELECTING → BOUND: DORA; lease from 0:00:00. T1 12:00:00, T2 21:00:00
12:00:00 RENEWING → BOUND: Unicast REQUEST, ACK at once. New lease: T1 24:00:00, T2 33:00:00, expiry 36:00:00
20:00:00 BOUND: R1's DHCP server stops. The laptop doesn't notice
24:00:00 RENEWING: Unicast REQUEST: no answer. 32,400 s to T2, so wait 16,200 s
28:30:00 RENEWING: No answer; wait 8,100 s
30:45:00 to 32:57:53 RENEWING: Seven more tries, each wait half the last: 4,050 s, 2,025, 1,012, 506, 253, 127, 63
32:58:56 RENEWING: Only 64 s to T2: the wait is clamped to 60 s
32:59:56 RENEWING: Last try. Another 60 s would pass T2: stop
33:00:00 REBINDING: Broadcast REQUEST: no answer. 10,800 s left on the lease, so wait 5,400 s
34:30:00 to 35:59:35 REBINDING: Eight more broadcasts, waiting 2,700 s, 1,350, 675, 337, 169, 84 and 60 between them; another 60 s would pass expiry
36:00:00 INIT: Lease expires. Address and default route removed
36:00:00 to 36:09:31 SELECTING: DISCOVERs after 4.4, 8.0, 15.8, 31.9, then about 64 s each
36:10:34.754 SELECTING → REQUESTING: The 14th DISCOVER since expiry finds R1 back; DORA, same address
36:10:39.878 BOUND: ARP probe clean; new lease from 36:10:34.754

That's 11 unicast REQUESTs during RENEWING (one at T1 and ten retries), 9 broadcasts during REBINDING, and 14 DISCOVERs after expiry. The waits come from halving whole seconds, with the 60-second floor; the DISCOVER intervals carry the random ±1 s, which in the simulator below is seeded so the numbers are repeatable. The laptop kept working normally until 36:00, sixteen hours after the server died. That's the whole point of a lease with T1 at 50%: a DHCP server can be down for a long time before anyone notices, as long as it's back before the leases run out.

Rebooting: INIT-REBOOT

The laptop at 40 hours is switched off and on again. Its lease, granted at 36:10, still has 20 hours to run, and it remembers it. Rather than start from scratch, it enters INIT-REBOOT and broadcasts a REQUEST that just asks R1 to confirm: the requested-IP option says 192.168.10.10, there's no server identifier, and ciaddr is zero (it isn't sure yet the address is still good). It waits in REBOOTING, and R1, which has the lease on record, ACKs it with a fresh 24 hours. Two messages instead of four.

Clients do the same when the link goes down and comes back, because they might have been plugged into a different network in between. Wi-Fi roaming between access points of the same network, a cable unplugged for a second, a laptop waking from sleep: each can trigger an INIT-REBOOT. (A switch running classic spanning tree, with no PortFast on the access port, holds the port blocked for 30 seconds after link-up, long enough for that first REQUEST to vanish, as the Spanning Tree article warned.)

When the answer is no: DHCPNAK

INIT-REBOOT is also where the laptop finds out it has moved. Carry it to the guest room and plug it into an access port in VLAN 30, and its INIT-REBOOT REQUEST for 192.168.10.10 arrives at R1's eth0.30 interface, 192.168.30.1. R1 can see that 192.168.10.10 isn't in 192.168.30.0/24, so it answers with a DHCPNAK: "that address is wrong here". The NAK goes to 255.255.255.255, always, when the server sends it directly (a relayed NAK goes to giaddr), because the laptop's idea of its own address is exactly what can't be trusted. It carries the server identifier, the client identifier, and a human-readable reason in option 56:

R1 → broadcast   192.168.30.1:67 → 255.255.255.255:68   xid 9b07d2e4
                 35 01 06                        message type 6, NAK
                 36 04 c0 a8 1e 01               server identifier 192.168.30.1
                 3d 07 01 02 00 00 aa bb 01      client identifier
                 38 0d 77 72 6f 6e 67 20 6e 65 74 77 6f 72 6b      "wrong network"
                 ff

The laptop throws away its remembered lease and goes to INIT, and a normal DORA on VLAN 30 gets it a guest address. A server that has no record of a client in INIT-REBOOT must say nothing at all, rather than NAK: there might be another, unrelated DHCP server on the same network that does know the client. Servers that are sure they're the only one, like a home router, can be told so (dnsmasq calls it dhcp-authoritative) and NAK unknown requests straight away, which saves the client waiting out its retries.

Checking the address: the ARP probe and DHCPDECLINE

A DHCP server's records can be wrong. Somebody may have configured a machine by hand with an address inside the pool, or a server may have lost its lease file in a crash. So RFC 2131 asks for a check at each end. The server should probe an address before offering it, typically with an ICMP echo (dnsmasq does this by default). And the client should check the address it has been given before using it, with ARP.

The client's check is the ARP probe from the ARP article, as RFC 5227 (2008) defines it: an ARP request for the new address, sent from 0.0.0.0 so as not to pollute anybody's cache. The client waits a random 0–1 s, sends three probes 1 to 2 s apart, and listens for 2 more seconds. If nobody answers, it announces the address with two ARP announcements and starts using it. That's why it can take a few seconds after the ACK before an address actually appears on the interface.

If somebody does answer, the client sends a DHCPDECLINE. Here's one from a phone that has just been given 192.168.10.11, only for a Raspberry Pi that somebody configured by hand at that address to answer its probe. R1 did ping .11 before offering it, but the Pi's firewall drops pings, so the ping check saw nothing:

phone → broadcast   0.0.0.0:68 → 255.255.255.255:67   xid 0e6b3f52
                    35 01 04                        message type 4, DECLINE
                    3d 07 01 02 00 00 aa bb 09      client identifier
                    32 04 c0 a8 0a 0b               requested IP 192.168.10.11
                    36 04 c0 a8 0a 01               server identifier 192.168.10.1
                    ff

It's broadcast from 0.0.0.0, because the phone has just refused the only address it had, and its ciaddr is zero. The server marks the address as unusable (Kea puts it "on probation" for 24 hours by default; dnsmasq disables a reserved address for 10 minutes) and tells the administrator something is wrong. The phone waits at least ten seconds, as RFC 2131 requires to stop a misbehaving pair from looping, and starts again from INIT. Its next offer is 192.168.10.12.

Leaving politely, and asking without leasing

Two last message types finish the set:

  • DHCPRELEASE (7): "I'm done with 192.168.10.10." Unicast to the server, with ciaddr set, the client identifier and the server identifier, and nothing else. The server puts the address back in the pool. It's entirely optional, and many clients don't bother when they shut down; they keep their lease for next time, and DHCP works perfectly well without it. You'll see one from dhclient -r, which gives an address up deliberately.
  • DHCPINFORM (8): "I already have an address; just tell me the rest." A machine configured by hand, like that Raspberry Pi at 192.168.10.11, can send an INFORM with ciaddr set to its address and ask for the DNS server and domain. The server replies with an ACK that has no lease time and yiaddr left at zero: nothing has been leased.

The client state machine

Put all of that together and you get the client state machine from RFC 2131's Figure 5, eight states and the messages that move between them:

INIT-REBOOT REBOOTING INIT SELECTING REQUESTING BOUND RENEWING REBINDING boot or link-up, lease remembered boot, no lease send REQUEST (option 50) ACK send DISCOVER OFFER: send REQUEST ACK, ARP probe clean T1: unicast ACK T2: broadcast ACK NAK, or ARP conflict: DECLINE NAK NAK, or lease expires

In pseudocode, the client's main loop is short, because the RFC leaves so few decisions open:

def dhcp_client(iface):
    lease = load_saved_lease(iface)
    if lease and not lease.expired():
        state = INIT_REBOOT                       # confirm what we remember
        reply = broadcast_request(requested_ip=lease.ip)          # REBOOTING
        if reply is ACK and arp_probe_clear(reply.yiaddr):
            lease = bind(reply)
        elif reply is NAK:
            lease = None                          # wrong network: start over
    while True:
        if lease is None:                         # INIT
            offer = broadcast_discover_with_backoff()             # SELECTING
            reply = broadcast_request(requested_ip=offer.yiaddr,
                                      server_id=offer.server_id)  # REQUESTING
            if reply is ACK and arp_probe_clear(reply.yiaddr):
                lease = bind(reply)               # BOUND: set T1, T2, expiry
            else:
                if reply is ACK: broadcast_decline(reply.yiaddr); sleep(10)
                continue
        sleep_until(lease.t1)
        reply = None
        while now() < lease.t2:                   # RENEWING
            reply = unicast_request(to=lease.server, ciaddr=lease.ip)
            if reply: break
            sleep(max((lease.t2 - now()) / 2, 60))
        while not reply and now() < lease.expiry: # REBINDING
            reply = broadcast_request(ciaddr=lease.ip)
            if not reply: sleep(max((lease.expiry - now()) / 2, 60))
        if reply is ACK:
            lease = bind(reply)                   # back to BOUND
        else:
            deconfigure(iface); lease = None      # NAK or expiry: INIT

Watch it happen. The simulator runs one laptop through the whole life cycle above, with a seeded random number generator for the retry jitter and the ARP probe timings, so the default run reproduces the table exactly.

The scenario

Times are h:mm:ss since the laptop's first DISCOVER (or plain seconds).

Client state

Event log

The Server Side

A DHCP server is, at heart, a small database with a UDP socket in front of it. For each subnet it serves (a scope, in Microsoft's terms) it keeps:

  • a pool: the range of addresses it may hand out;
  • the options that go with that subnet: mask, router, DNS servers, domain, lease time;
  • reservations: specific addresses for specific clients;
  • and the lease database: who has what, until when.

R1 serves three scopes, one per VLAN, because a DISCOVER broadcast on VLAN 20 can only ever reach R1's eth0.20 interface. The interface a request arrived on tells R1 which pool to use, and which of its own addresses to put in the server identifier.

Scope Pool Lease
VLAN 10, trusted .10 to .199 24 h
VLAN 20, IoT .10 to .199 24 h
VLAN 30, guests .10 to .199 2 h

Each pool is .10 to .199 of its VLAN's /24, and in each scope R1 names its own .1 address there as router and DNS server: 192.168.20.1 on VLAN 20, and so on.

Guests get a two-hour lease so that their addresses come back quickly after they leave; a busy café might use 30 minutes. A network where nothing moves can use a week. The trade-off is between how long a departed device keeps an address tied up and how much renewal traffic the server handles: with T1 at 50%, a two-hour lease means a renewal every hour from each guest.

Choosing an address

When a DISCOVER arrives, RFC 2131 says which address to offer, in order of preference:

  1. The client's current lease

    If it already has one, offer the same address.

  2. Its previous lease

    An expired or released one, if that address is still free.

  3. The address it asked for

    Option 50 in the DISCOVER, if valid and free.

  4. Anything else free

    From the pool for the subnet the request came from.

That ordering is why your laptop gets the same address day after day without a reservation: the server remembers it, even after the lease has lapsed, as long as nobody else has taken it. How a server picks "anything else" is up to it. Kea's default takes the next free address in order; dnsmasq normally derives one from a hash of the client's MAC address, so a client tends to land on the same address even if the lease file is lost. Our R1 is set to hand new addresses out in order. The laptop, first to ask, got 192.168.10.10, the start of the pool, and the phone got .11 and then, after its DECLINE, .12. The other machines from the VLANs article (the desktop on .10.40, the TV on .20.50, the guest laptop on .30.100) have held their leases for a while, and R1 keeps giving them the same addresses back by the rules above.

Reservations

Some machines should always have the same address: the NAS, so that bookmarks and backups keep working, and the printer, so the laptop can find it across VLANs. Rather than configure them by hand, and risk the conflicts above, you tell the server to reserve an address for their MAC addresses. They still run DHCP and still get their mask, router and DNS from the server, so if those ever change, they change everywhere.

  • NAS: 02:00:00:aa:bb:04 always gets 192.168.10.30.
  • Printer: 02:00:00:aa:bb:03 always gets 192.168.20.20.

Reservations can sit inside the pool, as these do, or outside it; the server simply never offers a reserved address to anybody else. The laptop needs no reservation: it gets .10 back every time by the rules above.

The lease database

The server writes every lease to stable storage, so that a reboot doesn't make it forget who has what and start handing out duplicates. dnsmasq keeps it as a text file, one lease per line: expiry time (seconds since 1970), MAC address, IP address, host name, and client identifier. Here are the laptop and the NAS, just after 09:00 on 29 October 2026:

$ cat /var/lib/misc/dnsmasq.leases
1793350800 02:00:00:aa:bb:01 192.168.10.10 laptop 01:02:00:00:aa:bb:01
1793350800 02:00:00:aa:bb:04 192.168.10.30 nas 01:02:00:00:aa:bb:04

1793350800 is 09:00 UTC on 30 October, 24 hours later. Because dnsmasq is also R1's DNS forwarder, it puts each client's host name into DNS as well: laptop.home.arpa now resolves to 192.168.10.10. Larger servers keep leases in SQL databases, and can share them between two servers for failover, which is where REBINDING's "ask anybody" earns its keep.

Relays: One Server, Many VLANs

Broadcasts don't cross routers, so a DHCP server can only hear DISCOVERs from the links it's directly attached to. That's fine for R1, which has an interface in each of the house's three VLANs. But an office with two hundred VLANs doesn't want two hundred DHCP servers. It wants one pair, in the data centre, and relay agents on the routers that forward DHCP to them.

To see how that works, change one thing about the house. Suppose switch B, the one in the study, is replaced by a layer-3 switch (the SVI design from the VLANs article) that now routes VLANs 20 and 30. It owns 192.168.20.1 and 192.168.30.1, and reaches R1 over VLAN 10 from 192.168.10.2. R1 no longer has an interface on VLAN 20 at all. When the TV in VLAN 20 is switched on, its DISCOVER reaches switch B, and switch B relays it:

TV · VLAN 20 …aa:bb:06 Switch B · relay .20.1 · .10.2 R1 · server 192.168.10.1 DISCOVER 0.0.0.0:68 → bcast:67 DISCOVER, relayed .10.2:67 → .10.1:67 giaddr .20.1 · hops 1 · +82 OFFER .20.50 .10.1:67 → .20.1:67 · 82 echoed OFFER .20.1:67 → .20.50:68 · no 82
  1. The relay fills in giaddr

    Switch B is configured as a relay on its VLAN 20 interface, with R1 as the server (Cisco calls this an ip helper-address). It takes the DISCOVER, writes its own VLAN 20 address, 192.168.20.1, into giaddr, adds one to hops, and sends the result as an ordinary unicast to 192.168.10.1, from port 67 to port 67. Everything else, the TV's MAC, its xid, its options, is passed on untouched.

  2. The server picks a pool by giaddr

    R1 sees a non-zero giaddr. It doesn't use the IP source address, 192.168.10.2, or the interface the packet arrived on: giaddr is inside 192.168.20.0/24, so the address comes from the VLAN 20 pool, and the router option it sends is 192.168.20.1. It offers the TV 192.168.20.50.

  3. Replies go back to the relay

    With giaddr set, RFC 2131 says the server sends its reply to the relay, to 192.168.20.1 port 67 (the server port, not 68). Switch B receives it and delivers it to the TV on VLAN 20, unicast or broadcast according to the broadcast flag, just as a local server would.

The hops count protects against relays forwarding to each other in a loop: RFC 1542 says a relay should discard a message whose hops exceeds 16 (RFC 1542 suggests a configurable default of 4). And because giaddr survives in the reply, the server's answer always finds its way back to the right subnet, however many routers lie in between.

Option 82: telling the server where the request came from

giaddr tells the server which subnet a client is on. Sometimes it needs to know more: which switch port, which customer line, which building. RFC 3046 (2001) lets a relay append a relay agent information option, number 82, with two sub-options: a circuit ID naming where the request came in, and a remote ID naming the remote end of that circuit (here, the relay itself). Their contents are up to the relay. Our switch B writes plain text:

52 18                                      option 82, length 24
   01 0c 70 6f 72 74 32 2d 76 6c 61 6e 32 30   circuit ID: "port2-vlan20"
   02 08 73 77 69 74 63 68 2d 62               remote ID:  "switch-b"
ff                                         end

It goes after the client's options, just before the end. The server can use it in policy ("only one address per port", "this port always gets .50"), must echo it unchanged in its reply, and the relay removes it before passing the reply to the client, which never sees it. ISPs use option 82 to tie an address to the physical line a customer is on, and, as we'll see next, switches use it to stamp requests they have vouched for.

Privacy: Random MAC Addresses

Look at what a DHCP client volunteers to anyone listening on the network: a MAC address that never changes, in chaddr and in the client identifier; a host name, often the owner's name ("Sams-iPhone"); and a parameter request list whose exact options and order identify the operating system and its version, a fingerprint some network products use on purpose. Carry a phone from café to airport to office and every network gets the same identifiers, which is excellent for anyone who wants to follow it around.

Phones and laptops now fight this with MAC address randomisation. Since Android 10 (2019) and iOS 14 (2020), devices join each Wi-Fi network with a randomly generated, locally administered MAC address instead of their hardware one, a different one for each network. Usually it's stable per network: Android derives it from the network's name and security type, and Apple's "Fixed" private address, the default for WPA2 or better networks, stays the same for as long as you don't forget the network. Some modes rotate: Apple's "Rotating" option, the default on open networks in iOS 18, changes the address every two weeks, and Android 12 can re-randomise on some networks once a day.

Anonymity profiles for DHCP, from RFC 7844 (2016), tell such clients to make DHCP match: base the client identifier on the randomised MAC, request as few options as possible, and leave out the host name.

That's good for privacy and awkward for a DHCP server, which uses the MAC to recognise a client:

  • Reservations break. A reservation is keyed on a MAC address. If the phone joins with a new one, the server has never heard of it and hands out an ordinary pool address.
  • "The same address every day" breaks too. A rotating MAC is a new client as far as the server can tell, so the old lease sits unused until it expires while the pool fills with ghosts. Short lease times on guest networks limit the damage.
  • Anything keyed on the MAC (parental controls, "block this device", traffic statistics per device) sees a stranger.

The cure for a device you want to recognise, like a phone you've given a reservation, is to turn the private address off for that one network, which both Android and iOS allow. Our house's wired machines use the same MAC forever, so the NAS and printer reservations are safe.

Rogue Servers

DHCP has the same weakness as ARP: a client trusts the first answer it gets, and the protocol has no way to tell a real server from an impostor. (RFC 3118 defined authentication for DHCP in 2001; almost nobody deployed it.) Most rogue servers are accidents: somebody plugs a home router into an office socket the wrong way round, and its DHCP server starts handing out 192.168.0.x addresses that lead nowhere. But a deliberate one is worse. Whoever answers first chooses the client's default gateway and DNS server, and so can put themselves in the middle of everything the client does. Another attack, starvation, floods the real server with DISCOVERs from thousands of made-up MAC addresses until its pool is empty. There's deliberately no attack demo on this page; the defences are the useful part.

DHCP snooping, on managed switches, is the main one. The switch watches every DHCP message, and each port is either trusted (where the real server or the uplink towards it lives) or untrusted (everything users plug into):

  • Server messages, OFFER, ACK and NAK, arriving on an untrusted port are dropped. A rogue server plugged into a desk socket can shout all it likes; no client hears it.
  • Client messages are checked: a DISCOVER whose chaddr doesn't match the frame's source MAC, or a RELEASE for somebody else's lease, is dropped too.
  • The switch records each lease it sees acknowledged in a binding table: this MAC, this IP, this VLAN, this port, until this time. That table is what Dynamic ARP Inspection checks ARP packets against, and what IP source guard uses to drop packets from addresses a port was never given. Snooping is the half of the ARP article's defence that this article promised.
  • Snooping switches typically insert option 82 into the requests they forward, naming the port, so that the server, and the switch itself on the way back, know exactly which socket a lease belongs to.

Add port security, which limits how many MAC addresses a port may use, and starvation goes too: one desk socket can't pretend to be a thousand laptops.

TunnelVision

In May 2024, researchers at Leviathan Security showed that a rogue DHCP server could quietly defeat many VPNs. The trick, TunnelVision (CVE-2024-3661), uses option 121, the classless static route option from RFC 3442, which lets a server push extra routes to a client. A VPN client normally routes everything into its tunnel with broad routes (often 0.0.0.0/1 and 128.0.0.0/1). The attacker's DHCP server pushes routes more specific than the VPN's own, say a handful of /2s, or a /32 for one target, through the attacker's own gateway. Longest-prefix match (from Routing Basics) then prefers the attacker's routes, and traffic leaves outside the tunnel while the VPN still says "connected". Android was unaffected for the simplest of reasons: it doesn't implement option 121. The fixes are on the client side: VPNs that use firewall rules or separate network namespaces to forbid traffic outside the tunnel, rather than relying on the routing table alone. On the network side, DHCP snooping stops the rogue server from being heard in the first place.

IPv6: SLAAC and DHCPv6

IPv6 hosts usually don't need a DHCP server for their addresses at all. As the IPv6 article showed, the laptop builds its own with SLAAC: R1's Router Advertisement on VLAN 10 carries the prefix 2001:db8:1234:10::/64, and the laptop appends an interface ID to get 2001:db8:1234:10:0:ff:feaa:bb01. The same advertisement gives it a default gateway (R1's link-local address) and a DNS server. No lease, no server, no state.

DHCPv6 (RFC 8415, 2018, which consolidated the original RFC 3315 of 2003 and its follow-ups) exists for networks that want a server to assign and track addresses, for hosts that need settings an RA can't carry, and for one job nothing else can do: handing out whole prefixes. The RA's flags tell hosts which to use, as the IPv6 article's table showed: M ("managed") means "get addresses from DHCPv6", O ("other") means "ask DHCPv6 for other settings, such as DNS servers", while addresses still come from SLAAC, via each prefix's A flag. R1 sends both as zero, so the laptop never speaks DHCPv6 on VLAN 10.

It's the same idea as DHCPv4, redesigned rather than extended:

DHCPv4 DHCPv6
Ports 68 → 67 546 → 547
Sent to 255.255.255.255 ff02::1:2 (all relays and servers)
From 0.0.0.0 Its link-local address
Exchange Discover, Offer, Request, Ack Solicit, Advertise, Request, Reply
Identity MAC, or option 61 DUID, always
Addresses yiaddr: one IA_NA: any number
Gateway Option 3 Never: RAs only

The biggest practical difference is in the "From" row. An IPv6 host always has a working link-local address before it starts DHCP, so DHCPv6 never needs the 0.0.0.0 and broadcast-flag gymnastics: the client multicasts from fe80::… to ff02::1:2 and servers simply unicast back. There's no broadcast in IPv6 at all.

The other ideas map across:

  • Message types. Solicit (1), Advertise (2), Request (3) and Reply (7) are the DORA of DHCPv6. Renew (5) and Rebind (6) are T1 and T2, Release (8) and Decline (9) work as before, and Information-request (11) is INFORM. A client and server that both support the Rapid Commit option can shorten the exchange to Solicit and Reply.
  • The header is four bytes: a message type and a 24-bit transaction ID. There are no fixed fields at all; everything, addresses included, is an option, with 16-bit codes and lengths.
  • DUIDs. Every client and server has a DHCP Unique Identifier that is meant to stay the same for the life of the device, whatever interface it's using. RFC 8415 defines four kinds: DUID-LLT (link-layer address plus a timestamp, type 1), DUID-EN (vendor-assigned, type 2), DUID-LL (link-layer address only, type 3) and DUID-UUID (type 4).
  • Identity associations. Addresses are requested inside an IA_NA (option 3) option, an "identity association for non-temporary addresses", which has its own ID and its own T1 and T2 and can hold several addresses. RFC 8415 recommends T1 and T2 of 0.5 and 0.8 times the shortest preferred lifetime, so the second fraction is a little smaller than DHCPv4's 0.875.

Prefix delegation: how R1 got its /56

Every IPv6 address in the house starts with 2001:db8:1234, and the series has said since the IPv6 article that the ISP delegated that /56 to R1. This is the protocol that did it: DHCPv6 prefix delegation, in which the client asks for an IA_PD (option 25), an identity association for prefix delegation, and the server answers with an IAPREFIX (option 26) inside it. R1 is the requesting router and R2, the ISP's edge router, is the delegating router.

When R1's WAN port, eth1, comes up, it does this alongside the DHCPv4 exchange that gets it 198.51.100.23:

  1. Solicit, from R1

    From fe80::ff:fecc:dd03 port 546 to ff02::1:2 port 547: "I'd like a prefix, a /56 if you have one." That's an IA_PD with ID 1 holding an IAPREFIX of ::/56, a hint about the size.

  2. Advertise, from R2

    "I can give you 2001:db8:1234::/56, preferred for a day, valid for two." T1 and T2 are 43,200 and 69,120 s: 0.5 and 0.8 of the preferred lifetime.

  3. Request and Reply

    R1 asks for exactly that, naming R2's DUID as the server, and R2 confirms. R2 then installs the route the Routing Basics article showed: 2001:db8:1234::/56 via R1's link-local address.

Here is the Solicit's DHCPv6 payload, all 69 bytes (the UDP checksum, computed over the IPv6 pseudo-header, is cc d9):

01 5f 3a 21                         Solicit, transaction ID 5f3a21
00 01 00 0a                         option 1, client ID, 10 bytes:
   00 03 00 01 02 00 00 cc dd 03       DUID-LL, Ethernet, R1's WAN MAC
00 08 00 02 00 00                   option 8, elapsed time: 0
00 19 00 29                         option 25, IA_PD, 41 bytes:
   00 00 00 01                         IAID 1
   00 00 00 00 00 00 00 00             T1 0, T2 0: "you decide"
   00 1a 00 19                         option 26, IAPREFIX, 25 bytes:
      00 00 00 00 00 00 00 00             preferred 0, valid 0
      38                                  prefix length 56
      00 00 00 00 00 00 00 00             prefix :: (a size hint only)
      00 00 00 00 00 00 00 00

With the /56 in hand, R1 carves out one /64 per VLAN, 2001:db8:1234:10::/64, :20::/64 and :30::/64, assigns itself ::1 in each and starts advertising them. When the lease is renewed at T1, nothing changes. If the ISP ever hands out a different prefix, every address in the house changes with it, which is why some ISPs promise a "static" delegation.

The two protocols even talk to each other now. RFC 8925 (2020) added DHCPv4 option 108, "IPv6-only preferred": a client that can live without IPv4 says so in its parameter request list, and a server on an IPv6-only network answers with option 108, telling it to skip IPv4 entirely.

Watching It Happen

Reading a capture

tcpdump decodes DHCP fully when you add enough -vs. Here is the laptop's DORA, captured on R1's VLAN 10 interface:

r1# tcpdump -n -vvv -i eth0.10 port 67 or port 68
09:00:00.104233 IP (tos 0x0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 328)
    0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 02:00:00:aa:bb:01, length 300, xid 0x3c41e9a7, Flags [none] (0x0000)
          Client-Ethernet-Address 02:00:00:aa:bb:01
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message (53), length 1: Discover
            Client-ID (61), length 7: ether 02:00:00:aa:bb:01
            Hostname (12), length 6: "laptop"
            Parameter-Request (55), length 4:
              Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6), Domain-Name (15)
            END (255), length 0
            PAD (0), length 0, occurs 33
09:00:00.105019 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 334)
    192.168.10.1.67 > 192.168.10.10.68: [udp sum ok] BOOTP/DHCP, Reply, length 306, xid 0x3c41e9a7, Flags [none] (0x0000)
          Your-IP 192.168.10.10
          Client-Ethernet-Address 02:00:00:aa:bb:01
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message (53), length 1: Offer
            Client-ID (61), length 7: ether 02:00:00:aa:bb:01
            Server-ID (54), length 4: 192.168.10.1
            Lease-Time (51), length 4: 86400
            RN (58), length 4: 43200
            RB (59), length 4: 75600
            Subnet-Mask (1), length 4: 255.255.255.0
            Default-Gateway (3), length 4: 192.168.10.1
            Domain-Name-Server (6), length 4: 192.168.10.1
            Domain-Name (15), length 9: "home.arpa"
            END (255), length 0
09:00:00.106871 IP (tos 0x0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 328)
    0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 02:00:00:aa:bb:01, length 300, xid 0x3c41e9a7, Flags [none] (0x0000)
          Client-Ethernet-Address 02:00:00:aa:bb:01
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message (53), length 1: Request
            Client-ID (61), length 7: ether 02:00:00:aa:bb:01
            Requested-IP (50), length 4: 192.168.10.10
            Server-ID (54), length 4: 192.168.10.1
            Hostname (12), length 6: "laptop"
            Parameter-Request (55), length 4:
              Subnet-Mask (1), Default-Gateway (3), Domain-Name-Server (6), Domain-Name (15)
            END (255), length 0
            PAD (0), length 0, occurs 21
09:00:00.107402 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 334)
    192.168.10.1.67 > 192.168.10.10.68: [udp sum ok] BOOTP/DHCP, Reply, length 306, xid 0x3c41e9a7, Flags [none] (0x0000)
          Your-IP 192.168.10.10
          Client-Ethernet-Address 02:00:00:aa:bb:01
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message (53), length 1: ACK
            Client-ID (61), length 7: ether 02:00:00:aa:bb:01
            Server-ID (54), length 4: 192.168.10.1
            Lease-Time (51), length 4: 86400
            RN (58), length 4: 43200
            RB (59), length 4: 75600
            Subnet-Mask (1), length 4: 255.255.255.0
            Default-Gateway (3), length 4: 192.168.10.1
            Domain-Name-Server (6), length 4: 192.168.10.1
            Domain-Name (15), length 9: "home.arpa"
            END (255), length 0

Everything in this article is there:

  • The addressing. 0.0.0.0.68 > 255.255.255.255.67 for the client's broadcasts, 192.168.10.1.67 > 192.168.10.10.68 for R1's unicast replies; flags [none] (no Don't Fragment) on the client's hand-built packets and [DF] on the server's.
  • [udp sum ok]. tcpdump checked the same checksums we computed, cb35 and friends.
  • Request and Reply. That's BOOTP's op field; the DHCP message type is the DHCP-Message (53) line underneath.
  • length 300 for the client's padded messages, 306 for R1's, and PAD (0), length 0, occurs 33: the 33 padding bytes after the DISCOVER's end option.
  • RN (58) and RB (59) are tcpdump's names for T1 and T2.

On a machine with more than one DHCP server, or a rogue one, you'll see two OFFERs with the same xid and different Server-IDs, which is a quick way to find it. Add -e to see the Ethernet addresses as well, and you can confirm the OFFER went to 02:00:00:aa:bb:01 rather than ff:ff:ff:ff:ff:ff.

dnsmasq and Kea

Two servers cover most of the open-source world. dnsmasq, by Simon Kelley, is a small DNS forwarder and DHCP server in one, and it's what most home routers and OpenWrt run. R1's configuration is a handful of lines:

# /etc/dnsmasq.conf on R1 (DHCP part)
interface=eth0.10
interface=eth0.20
interface=eth0.30
domain=home.arpa
dhcp-authoritative
dhcp-sequential-ip
dhcp-range=192.168.10.10,192.168.10.199,255.255.255.0,24h
dhcp-range=192.168.20.10,192.168.20.199,255.255.255.0,24h
dhcp-range=192.168.30.10,192.168.30.199,255.255.255.0,2h
dhcp-host=02:00:00:aa:bb:04,192.168.10.30,nas
dhcp-host=02:00:00:aa:bb:03,192.168.20.20,printer

dnsmasq picks the right dhcp-range from the interface each request arrives on, sends its own address on that interface as router and DNS server unless told otherwise, and with dhcp-sequential-ip picks new addresses in order rather than by hash.

Kea, from ISC, is the successor to the venerable ISC DHCP server, which ISC stopped maintaining at the end of 2022. It's built for larger networks: JSON configuration, SQL lease databases, high availability between two servers, and a REST API. The same VLAN 10 scope looks like this:

{ "Dhcp4": {
    "interfaces-config": { "interfaces": [ "eth0.10" ] },
    "valid-lifetime": 86400,
    "subnet4": [ {
        "id": 10,
        "subnet": "192.168.10.0/24",
        "pools": [ { "pool": "192.168.10.10 - 192.168.10.199" } ],
        "option-data": [
            { "name": "routers", "data": "192.168.10.1" },
            { "name": "domain-name-servers", "data": "192.168.10.1" },
            { "name": "domain-name", "data": "home.arpa" } ],
        "reservations": [
            { "hw-address": "02:00:00:aa:bb:04", "ip-address": "192.168.10.30" } ]
    } ]
} }

Kea doesn't send T1 and T2 by default unless renew-timer and rebind-timer are set, so its clients use the 50% and 87.5% defaults; set calculate-tee-times to make it compute them.

On the client side, look for the lease files your system keeps (/var/lib/dhcp/ for dhclient, NetworkManager and systemd-networkd each have their own), and for the log lines when an interface comes up: nearly every client logs its DISCOVER, OFFER, REQUEST and ACK, and the lease time it got.

Where to Go Next

  • NAT: the next article. R1 got one public address, 198.51.100.23, from the ISP's DHCP server and shares it with every private address it hands out.
  • DNS: what the laptop does with the DNS server DHCP gave it, and how laptop.home.arpa ended up in R1's answers.
  • ARP: the probes that check a new address, and the spoofing that DHCP snooping helps stop.
  • VLANs: the broadcast domains that decide which DHCP server a DISCOVER can reach.
  • IPv6: SLAAC, Router Advertisements and the M and O flags, the other way to get an address.
  • UDP: ports, broadcasts and the checksum we computed over 0.0.0.0.

Key Takeaways

  • DHCP (RFC 2131 and RFC 2132, 1997, after RFC 1531 in 1993) gives a host its address, mask, router, DNS servers and more, on a time-limited lease. It grew out of BOOTP (RFC 951, 1985), which replaced RARP (RFC 903, 1984), and keeps BOOTP's message format and ports.
  • DORA: DISCOVER (broadcast), OFFER, REQUEST (broadcast, naming the chosen server in option 54), ACK. The client sends from 0.0.0.0 port 68 to 255.255.255.255 port 67; replies go to port 68.
  • Both ports are fixed so a broadcast reply never lands on some other program's ephemeral port. The broadcast flag (80 00) asks the server to broadcast replies to clients that can't receive unicast before they're configured.
  • A DHCP message is a 236-byte fixed header (op, htype, hlen, hops, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file), the magic cookie 63 82 53 63, and type-length-value options ending in 255. Option 53 sets the message type. Messages are usually padded to 300 bytes.
  • The laptop's DISCOVER is 328 bytes on the wire (IP checksum 79a6, UDP cb35); R1's OFFER and ACK are 334 bytes and differ only in option 53.
  • Leases: T1 = 50% (renew, unicast to the granting server, ciaddr set), T2 = 87.5% (rebind, broadcast to any server), then expiry and INIT. Retries wait half the remaining time, at least 60 s; DISCOVERs back off 4, 8, 16, 32, 64 s with ±1 s of jitter.
  • INIT-REBOOT confirms a remembered lease with a broadcast REQUEST (option 50, no 54). A server that knows the address is wrong sends a broadcast NAK; one with no record stays silent.
  • Clients ARP-probe a new address (RFC 5227) and send a DECLINE on conflict, then wait at least 10 s. RELEASE gives an address back; INFORM asks for settings without a lease.
  • Servers keep pools per subnet, reservations by MAC, and a lease database on disk. They prefer the client's current or previous address, then option 50, then a free one.
  • Relays let one server serve many subnets: they set giaddr, which picks the pool, increment hops, and can add option 82 (circuit and remote ID), which the server echoes and the relay strips.
  • MAC randomisation (Android 10, iOS 14 and later) protects privacy and breaks reservations keyed on MACs. Rogue servers are stopped by DHCP snooping (trusted ports, a binding table that also feeds Dynamic ARP Inspection); TunnelVision (CVE-2024-3661) abused option 121 routes to bypass VPNs.
  • IPv6 hosts usually use SLAAC; the RA's M and O flags point them at DHCPv6 (UDP 546/547, ff02::1:2, Solicit, Advertise, Request, Reply, DUIDs, IA_NA). DHCPv6 never supplies a default gateway. Prefix delegation (IA_PD) is how R1 got 2001:db8:1234::/56 from R2.

The laptop now has an address, a gateway and a DNS server, all without anyone typing a thing. But look at that address again: 192.168.10.10 is private. It means nothing outside the house, and no server on the Internet could ever reply to it. Yet the laptop browses the web all day. Something at the edge of the network is rewriting addresses on every packet, and keeping a table of who's talking to whom. That's NAT.