§4.3.2–dhcpObtaining a Host Address: DHCP

Network layer Kurose & Ross pp. 339–343 · ~8 min read

  • dhcp
  • subnet

Where you are

  • Application layer
  • Transport layer
  • Network layer you are here
  • Link layer
  • Physical layer

A host that has just joined a network knows nothing at all, and four broadcast messages later it has an address, a mask, a default gateway and a name server.

Words you will meet

  • DHCP (Dynamic Host Configuration Protocol) — the protocol that hands a host its network configuration .
  • Plug-and-play, or zeroconf — what DHCP makes the network feel like.
  • Lease — the address is borrowed for a stated time, not given.
  • Default gateway — the address of the first-hop router.
  • Relay agent — a router that forwards DHCP messages to a server on another subnet.
  • yiaddr — “your Internet address”, the field carrying the address being allocated.

Why this matters

Section 4.3.2 explained what an address means. It did not say where a host gets one.

A network administrator configures routers by hand. Hosts could be done that way too, and once were. But consider the book’s example: a student carrying a laptop from a dormitory to a library to a classroom. Each location is a different subnet , so each needs a different address. It is unimaginable that an administrator would reconfigure laptops at each location, and few students except those taking a computer networking class could do it themselves.

So DHCP (Dynamic Host Configuration Protocol) does it. The interesting part is the bootstrapping problem it has to solve. How do you address a message to a host that has no address, on behalf of a host that has no address?

The bootstrapping problem

Look at what the arriving client knows when it joins: nothing. Not its own address. Not the address of the network it has attached to. Not whether a DHCP (Dynamic Host Configuration Protocol) server exists, let alone where.

It has exactly one identity — its MAC (Media Access Control) address, burned into the hardware — and one capability: the link layer can broadcast a frame to every node on the subnet.

That constraint shapes every message in the protocol.

Figure 4.24 — the four-step exchange
message 4 of 4
Arriving clientno address yetTimeDHCP server223.1.2.5TimeDHCP DISCOVERDHCP OFFERDHCP REQUESTDHCP ACK

Click any arrow to see what that message says and why it is sent.

Recreated with the book’s own values, transaction IDs included. Note that both server replies are broadcast, and that the client’s source address is 0.0.0.0 in both of its messages.

Read this diagram as text
  1. Arriving client sends DHCP DISCOVER to DHCP server. Broadcast, because the client knows nothing — not its address, not the subnet, not where a server is.
  2. DHCP server sends DHCP OFFER to Arriving client. Also broadcast. The client has no address, so there is nothing to send a unicast reply to.
  3. Arriving client sends DHCP REQUEST to DHCP server. The client accepts one offer and echoes the parameters back. The server ID says which offer, so other servers know theirs was declined.
  4. DHCP server sends DHCP ACK to Arriving client. Confirmed. Only now may the client use the address, and only for 3,600 seconds.

Lifelines, left to right: Arriving client (host), DHCP server (server).

The four steps, and why each is shaped as it is

1 — DHCP discover. The client sends a discover message in a UDP (User Datagram Protocol) segment to port 67. It travels inside an IP (Internet Protocol) datagram whose destination is 255.255.255.255, the broadcast address of section 4.3.2, and whose source is 0.0.0.0, meaning “this host”. The link layer broadcasts the frame to every node on the subnet.

2 — DHCP offer. A server replies with a proposed address in the yiaddr field, plus the network mask and a lease time. It is common for a server to set the lease to several hours or days.

The reply is also broadcast, and the book invites you to work out why. The reason is that a unicast reply would have to be addressed to the client — and the client still has no address. There is nothing to address it to.

3 — DHCP request. Several servers may have offered, so the client chooses one and echoes the configuration back. The server identifier names which offer it accepted, which is how the other servers learn theirs was declined and can release the address they had set aside.

4 — DHCP ACK (acknowledgement) . The server confirms. Only now may the client use the address, and only for the lease duration.

The same exchange, as bytes

DHCP — four messages, and a host that knew nothing is configured
No.TimeSourceDestinationProtocolLengthInfo
10.0000000.0.0.0255.255.255.255DHCP292DHCP Discover - Transaction ID 0x0000028e
20.002100223.1.2.5255.255.255.255DHCP316DHCP Offer - Transaction ID 0x0000028e
30.0043000.0.0.0255.255.255.255DHCP298DHCP Request - Transaction ID 0x0000028e
40.005800223.1.2.5255.255.255.255DHCP316DHCP ACK - Transaction ID 0x0000028e

Packet 1 Packet 1 of 4. The client has just joined the network and knows nothing — not its own address, not the subnet it is on, not where a server is. So it shouts. Source 0.0.0.0 because it has no address to use; destination 255.255.255.255 so every host on the subnet hears it. The link layer broadcasts the frame to all nodes.

Protocol tree — click a field

The actual bytes

0000 ff ff ff ff ff ff aa bb cc 00 00 2a 08 00 45 00 ...........*..E.
0010 01 16 4a 01 00 00 40 11 2f d7 00 00 00 00 ff ff ..J...@./.......
0020 ff ff 00 44 00 43 01 02 54 ca 01 01 06 00 00 00 ...D.C..T.......
0030 02 8e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040 00 00 00 00 00 00 aa bb cc 00 00 2a 00 00 00 00 ...........*....
0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00f0 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 00 00 00 00 00 00 00 00 ................
0110 00 00 00 00 00 00 63 82 53 63 35 01 01 37 04 01 ......c.Sc5..7..
0120 03 06 33 ff ..3.

The exchange of Figure 4.24, as bytes. Watch the source address in packets 1 and 3: still 0.0.0.0, because the address is not the client’s until packet 4 confirms it.

Three things to look for in the capture

The source address in packets 1 and 3 is 0.0.0.0. Not just in the discover — in the request as well. The client has been offered an address by then, but it does not own it until packet 4 acknowledges it, so it cannot use it as a source address. That is the difference between being offered something and having it.

Every destination is 255.255.255.255, including the server’s replies. Four broadcasts, heard by every host on the subnet, to configure one machine.

ciaddr is zero in all four messages, and yiaddr is filled in only by the server. Two adjacent fields; one is what the client has and one is what it is being given. The client is never in a position to fill in either.

Figure 4.24 uses two transaction IDs. A real exchange uses one.

The book’s figure shows transaction ID 654 on the discover and offer, then 655 on the request and acknowledgement.

RFC (Request For Comments) 2131 requires the client to reuse the same identifier for all four messages. It is the only thing tying the exchange together, because nothing else in these packets is unique to this client yet. A request with a new identifier would not be recognisable as an answer to that offer.

The ladder above reproduces the book’s figure as printed. The capture below it uses one identifier throughout, because it claims to be real bytes and a real capture would show one. If you compare the two and notice the difference, that is the reason.

The book’s numbering does make the pairing easier to see on paper, which is probably why it is drawn that way.

What the client ends up with

The offer and the acknowledgement carry more than an address. Look at options 1, 3 and 6 in packets 2 and 4 of the capture:

  • the address223.1.2.4, in yiaddr;
  • the subnet mask255.255.255.0, so the client can tell which addresses are on its own subnet;
  • the default gateway — the first-hop router, for everything that is not;
  • a DNS (Domain Name System) server — so that chapter 2.4’s name lookups can begin;
  • a lease time — 3,600 seconds here.
What the client was actually given
the address223.1.2.411011111.00000001.00000010.00000100
the mask255.255.255.011111111.11111111.11111111.00000000
subnet223.1.2.0/2411011111.00000001.00000010.00000000
last address223.1.2.25511011111.00000001.00000010.11111111
addresses in the block
256
usable for interfaces
254
host bits
8

The shaded bits are the network prefix — the 24 bits every interface on this subnet shares. The rest identify one interface within it. Two of the 256 are reserved: 223.1.2.0 names the subnet itself and 223.1.2.255 is its broadcast address, which is why the usable count is 256 − 2.

The offer carried an address and a mask. Together they say which addresses are on the same subnet — that is, which the client may reach directly, and which need the default gateway.

Why the mask is not optional

An address alone is not enough to send anything.

Given 223.1.2.4 and the mask 255.255.255.0, the client can compute that 223.1.2.0/24 is its own subnet. Now it can answer the only question that matters for every datagram it will ever send: is the destination on my subnet or not?

  • On it — deliver directly over the link.
  • Not on it — send to the default gateway, which is why that address came too.

Without the mask, a host with an address still could not send a single packet. That is why DHCP delivers the whole configuration and not just the address.

When there is no server on the subnet

The simple case has a DHCP server on every subnet. Often there is not.

Then a relay agent — typically a router — is configured with the address of a server for the network. In the book’s Figure 4.23, the server sits on subnet 223.1.2/24 and the router relays for arriving clients on 223.1.1/24 and 223.1.3/24.

The relay agent fills in the giaddr field with its own address. The server can then tell which subnet the request came from, and allocate an address from the right block. In this capture giaddr is zero, because the server is on the client’s own subnet.

DHCP’s one significant shortcoming

The book flags it directly, and it matters for chapter 7.

A new address is obtained every time a node connects to a new subnet. So a TCP (Transmission Control Protocol) connection to a remote application cannot be maintained as a mobile node moves between subnets.

Think about why: section 3.2 said a TCP connection is identified by a four-tuple that includes both IP addresses. Change one of them and it is a different connection. Or rather it is no connection at all, because the far end is still sending to an address the host no longer has.

Chapter 7 shows how mobile cellular networks let a host retain its IP address and its ongoing TCP connections while it moves between base stations. That is a genuinely different mechanism, and DHCP’s limitation is why it is needed.

Check yourself

Check yourself

0 of 6 answered
  1. 1.predictWhy is the DHCP server's offer broadcast rather than sent directly to the client?

    What would you address a unicast reply to?

  2. 2.predictIn the capture, what is the source address of packet 3 — the DHCP request — and why?

  3. 3.Besides an IP address, what else does DHCP deliver — and why is it needed?

  4. 4.The book's Figure 4.24 uses transaction ID 654 for the first two messages and 655 for the last two. What does RFC 2131 require?

  5. 5.A DHCP server sits on subnet 223.1.2/24. How do hosts arriving on 223.1.1/24 get an address?

  6. 6.predictA laptop with an open TCP connection moves from one subnet to another and gets a new address by DHCP. What happens to the connection?

What to remember

  • Four steps: discover, offer, request, acknowledge. Client messages go to port 67, server messages to port 68.
  • All four are broadcast to 255.255.255.255, including the server’s replies, because there is no address to send a unicast reply to. The client’s source address is 0.0.0.0 until the very end — being offered an address is not having one.
  • The address is a lease, not a gift — 3,600 seconds in this example, hours or days in practice, and renewable. One transaction ID ties the whole exchange together: the book’s figure shows two, and a real capture shows one.