How a new host gets an address
See how four DHCP messages give a host with no address its address, mask, router, DNS server and lease, across a relay, and how that lease ages. Host configuration and address translation · Computer networks.
A laptop joins a café network. Before it can load one web page it needs five facts it has never been told: its own IPv4 address, the subnet mask that says which addresses are its neighbours, the router that leads off the subnet, a DNS server that turns names into addresses, and how long it may keep all of that. It cannot even address a server, having no address itself. Dynamic Host Configuration Protocol (DHCP) solves this. How does a host with no address ask at all, and what keeps the answer from going stale?
Asking without an address
Take a laptop on the subnet 172.16.4.0/24. It knows no server and has no source address, so its first message goes out as a broadcast: source 0.0.0.0, destination 255.255.255.255, from UDP port 68 (client side) to UDP port 67 (server side). Every host on the subnet receives it, and any DHCP server there can answer.
The exchange has four messages, remembered as DORA. The laptop sends a Discover. Eligible servers may answer with an Offer of one address, which they may hold aside. The laptop broadcasts a Request that names the offer it takes. The chosen server answers with an Acknowledge, written ACK, which binds the address to the laptop.
Two servers share this link: Server A at 172.16.4.2 offers 172.16.4.60, and Server B at 172.16.4.4 offers 172.16.4.130. The laptop takes B's offer. In this example each server sends its Offer to the laptop's MAC address; a client can ask for a broadcast reply. B's ACK carries everything from the opening paragraph: address 172.16.4.130, mask 255.255.255.0, router 172.16.4.1, DNS server 172.16.4.3 and a lease of 8 hours. The DNS resolution lesson covers the later query. Option 6 supplies a resolver address; a DHCP server or client may separately perform a Dynamic DNS update, as noted at the end.
Why a Request after an Offer? An Offer is only a proposal, and more than one server may have made one. The laptop must say which it chose, and the broadcast Request lets every server hear. It carries the chosen server's address, the server identifier. B sees its own address and goes ahead. A sees another server's address, takes its offer back and can free 172.16.4.60 for the next client.
Two servers offer, one is chosen
Read the steps as text
- Laptop, MAC address 02:00:5e:10:00:21, has no IPv4 address yet. Two DHCP servers share the link and can answer.
- Laptop broadcasts a Discover from 0.0.0.0 port 68 to 255.255.255.255 port 67, because it has no address and knows no server. It reaches Server A and Server B.
- Server A offers 172.16.4.60 and marks it offered in the pool. The Offer goes from 172.16.4.2 port 67 to the client's MAC address and 172.16.4.60 port 68, because the client did not ask for a broadcast reply.
- Server B offers 172.16.4.130 and marks it offered in the pool. It sends the Offer the same way, from 172.16.4.4 port 67 to 172.16.4.130 port 68.
- Laptop may take any offer and takes the one from Server B, not the first to arrive. The Request is a broadcast naming server 172.16.4.4 and the address 172.16.4.130, so every server hears it.
- Server A sees that the Request names 172.16.4.4, the address of another server, so it takes back the offer and frees 172.16.4.60 in the pool.
- Server B binds 172.16.4.130 for the client: the pool row goes from offered to leased. The Acknowledge carries mask 255.255.255.0, router 172.16.4.1, DNS server 172.16.4.3 and lease 8 hours.
Across a subnet boundary
This limited broadcast stays on its local link, so a server elsewhere does not hear the Discover directly. A relay agent, usually the router on the client's subnet, carries DHCP broadcasts on. It adds one fact the server could not learn otherwise: its own address on the client's subnet, written into the giaddr (gateway address) field. In this example it unicasts the message to the server on port 67.
Take a laptop on 10.20.0.0/24 whose router has the address 10.20.0.1. A server named Central at 10.0.0.5 keeps three pools: 10.10.0.0/24, 10.20.0.0/24 and 10.30.0.0/24. Central reads giaddr 10.20.0.1, uses the configured mapping for 10.20.0.0/24 and offers an address from that pool, here 10.20.0.2, the first usable address that is not the router's.
The reply returns through the relay. Central addresses the Offer to giaddr, the relay, on port 67. The relay delivers it to the laptop on port 68. Here the server replies to port 67, rather than directly to the client on port 68. With a relay, the server talks to port 67 on the relay, and only the last hop uses port 68.
A relay carries the exchange to another subnet
Read the steps as text
- Laptop is on 10.20.0.0/24. The DHCP server Central is on another subnet, and Router, at 10.20.0.1 on the client's subnet, relays for it.
- Laptop broadcasts a Discover from 0.0.0.0 port 68 to 255.255.255.255 port 67. A broadcast stays on the subnet where it starts, so Router, the only DHCP-aware device there, picks it up.
- Router writes 10.20.0.1, the address it has on this subnet, into the giaddr field of the message. A server reads giaddr to find the subnet the client is on.
- Router sends the message on as a unicast from Router port 67 to Central at 10.0.0.5 port 67, so it can cross to the other subnet.
- Central finds 10.20.0.1 inside the pool 10.20.0.0/24, so it picks that pool and marks 10.20.0.2 offered. It leaves the other pools alone.
- Central sends an Offer of 10.20.0.2 with mask 255.255.255.0 to 10.20.0.1 port 67, the giaddr address. It answers Router, because the client has no address to send to yet.
- Router hands the Offer to Laptop from 10.20.0.1 port 67 to 10.20.0.2 port 68, addressed to the client's MAC address, because the client did not ask for a broadcast reply.
- Laptop broadcasts a Request for 10.20.0.2. Router sends it on to Central at 10.0.0.5 port 67 with the same giaddr, 10.20.0.1.
- Central binds 10.20.0.2: the pool row goes from offered to leased. Router delivers the Acknowledge to Laptop, so Laptop now has 10.20.0.2 and mask 255.255.255.0.
The relayed Acknowledge carries the router, DNS server and lease the same way; the scene follows only the address and mask. Once configured, the laptop sends ordinary packets to its router.
A lease that ages
The 8 hours in B's ACK is the lease: how long the laptop may keep the address, which lets a server reclaim addresses from hosts that left. RFC 2131 defines two timers with these defaults when the server does not supply its own: T1 is 0.5 of the lease and T2 is 0.875 of it. For an 8-hour lease T1 is 4 hours and T2 is 7 hours. A server may send either value as option 58 for T1 or 59 for T2; an omitted one keeps its default.
For these examples, requests and replies are instantaneous and the timers have no random adjustment. In RFC 2131 the lease expiry is the Request send time plus the lease duration; a delayed ACK does not extend it.
At T1 the laptop renews. It unicasts a Request to its own server, the one that granted the lease. An immediate ACK grants a fresh lease and T2 is never reached: a tablet renewing a 12-hour lease at 6 hours is leased again for a full 12.
The renewal is answered, the lease starts over
Read the steps as text
- Tablet is about to be granted a lease by Server A. Server B is another server on the link and is not asked.
- Tablet holds a lease from Server A. T1 is 6 hours, half of the lease. T2 is 10 hours 30 minutes, seven eighths of it. The lease ends at 12 hours.
- The clock runs 6 hours. The lease is 6 hours old, which is T1.
- At T1 Tablet unicasts a Request to Server A on port 67. Server A answers with an Acknowledge, and the lease starts over at 0 of 12 hours.
If no ACK has arrived by T2, the laptop rebinds. It broadcasts a Request, so any server may answer. Another server may extend the lease if it has authority, for example when a failover pair shares lease records. A server can also refuse a Request with a NAK, which makes the client stop using the address and restart. With no NAK, the laptop keeps using the address while its renewal is unanswered; if nobody has answered by lease expiry, it must drop the address and start again with a Discover.
Both examples start with an unanswered renewal. First, Server A has failed: the renewal at 4 hours gets no answer, and at 7 hours a broadcast reaches Server B, which extends the lease. In the second, a phone holds a 4-hour lease and no server answers at all.
The server is down, another one extends the lease
Read the steps as text
- Laptop is about to be granted a lease by Server A. Server B is another server on the link and shares Server A's lease records.
- Laptop holds a lease from Server A. T1 is 4 hours, half of the lease. T2 is 7 hours, seven eighths of it. The lease ends at 8 hours.
- The clock runs 4 hours. The lease is 4 hours old, which is T1.
- At T1 Laptop unicasts a Request to Server A on port 67. No answer comes. Laptop keeps using the address while the clock runs on.
- The clock runs 3 hours more. The lease is 7 hours old, which is T2.
- At T2 Laptop broadcasts a Request to 255.255.255.255 port 67 for any server. Server B, a server that has the lease record, answers with an Acknowledge. The lease starts over at 0 of 8 hours.
Nobody answers, the lease runs out
Read the steps as text
- Phone is about to be granted a lease by Server A. Server B is another server on the link; in this example it has no record of the lease and does not reply.
- Phone holds a lease from Server A. T1 is 2 hours, half of the lease. T2 is 3 hours 30 minutes, seven eighths of it. The lease ends at 4 hours.
- The clock runs 2 hours. The lease is 2 hours old, which is T1.
- At T1 Phone unicasts a Request to Server A on port 67. No answer comes. Phone keeps using the address while the clock runs on.
- The clock runs 1 hour 30 minutes more. The lease is 3 hours 30 minutes old, which is T2.
- At T2 Phone broadcasts a Request to 255.255.255.255 port 67 for any server. No server answers.
- The clock runs 30 minutes more. The lease is 4 hours old.
- The lease ends at 4 hours with no Acknowledge. Phone must stop using the address, drops it and goes back to sending a Discover.
A client that leaves cleanly can send a Release so its server may reuse the address; one that vanishes leaves the lease to run out.
Recap
- This host gets an address, a mask, a router, a DNS server address and a lease. The example uses four DHCP messages: a broadcast Discover, Offers, a broadcast Request that names one server so the others free their offers, and that server's ACK.
- A relay writes its own address into giaddr and unicasts to the server on port 67, so the server picks a configured pool and replies to the relay, which delivers on port 68.
- A lease ages on a clock. At T1 (0.5 of the lease) the client renews with its own server, at T2 (0.875) it rebinds by broadcast, and at expiry it drops the address and begins again with a Discover.
What this lesson leaves out
DHCP for IPv6 uses different messages and ports, and Router Advertisements often do the address work there; the IPv6 addressing lesson covers that. This lesson also leaves out the long list of options, server failover protocols, authentication, relay link-selection extensions, and the address check a client may run before using an address. The protocol is specified in RFC 2131, and the pairing of DHCP with Dynamic DNS is described in RFC 4702.
Continue to NAT and PAT state to follow what happens when a configured private host opens an Internet flow.