The idea
A laptop that has just plugged into a network needs an IP address before it can do anything else. The lecture frames this as two separate questions. The first is how a host gets an address within its own network, the host part. The second is how a network gets an address for itself, the network part. DHCP answers only the first.
A sysadmin could type the address into a config file such as
/etc/rc.config on UNIX. That does not suit a laptop that joins and leaves
networks all day. DHCP, the Dynamic Host Configuration Protocol, lets the
host ask a server for an address when it joins. The lecture calls it
“plug-and-play”.
NAT and DHCP already covers the message exchange from Lecture 5. This page follows Lecture 9, which adds what else DHCP returns and traces the exchange through the protocol stack.
How it works
Goal and four messages
The lecture states the goal as a host dynamically obtaining an IP address from a network server when it joins. It lists four properties:
- The host can renew its lease on an address in use.
- Addresses can be reused, because a host only holds one while it is connected.
- It supports mobile users who join and leave a network.
- It is plug-and-play.
The overview is four messages:
- The host broadcasts a DHCP discover message. The lecture marks this one optional.
- The DHCP server responds with a DHCP offer message. Also optional.
- The host requests the address with a DHCP request message.
- The server sends the address in a DHCP ack message.
How it works
The client-server scenario
The lecture’s scenario has a router joining three subnets, with hosts such as
223.1.1.1, 223.1.2.5 and 223.1.3.27. The DHCP server is 223.1.2.5. A new client arrives and needs
an address in this network.
Typically the DHCP server is co-located in the router, serving every subnet the router is attached to.
The message exchange in the lecture carries these details:
- Discover. Source
0.0.0.0, port68. Destination255.255.255.255, port67. The client has no address and does not know the server, so it broadcasts “is there a DHCP server out there?” with transaction ID654. - Offer. Sent from the server, port
67, to the broadcast address, port68. It proposes the address223.1.2.4and carries the same transaction ID654and a lifetime of3600secs. - Request. Source
0.0.0.0, port68, destination255.255.255.255, port67. The client says “OK, I would like to use this address”, echoing223.1.2.4, with a lifetime of3600secs. - Ack. Source
223.1.2.5, port67, destination the broadcast address, port68. The server confirms the address223.1.2.4and the3600secs lifetime.
The lecture notes that the first two steps can be skipped “if a client remembers and wishes to reuse a previously allocated network address” and cites RFC 2131.
Where marks get lost
Discover and offer are the optional pair
Only the first two messages can be skipped, and only when the client already remembers an address it wants to reuse. Request and ack always happen. A question that asks which messages are optional wants discover and offer.
How it works
DHCP returns more than an address
The lecture lists what DHCP can return besides the allocated address on the subnet:
- The address of the first-hop router for the client, which is the client’s gateway router.
- The name and IP address of the DNS server.
- The network mask, which says which part of the address is the network and which part is the host.
This is why a laptop needs nothing configured by hand. The address gives it an identity. The router address tells it where to send anything outside the subnet. The DNS address lets it turn names into addresses.
How it works
The lecture's example, layer by layer
The connecting laptop uses DHCP to obtain its IP address, the address of the
first-hop router and the address of the DNS server. The lecture shows the
router at 168.1.1.1 with the DHCP server built in.
- The DHCP request is encapsulated in UDP, encapsulated in IP, encapsulated in Ethernet.
- The Ethernet frame is broadcast on the LAN, destination
FFFFFFFFFFFF, and received at the router running the DHCP server. - At the router the frame is demultiplexed: Ethernet demux’ed to IP, IP demux’ed to UDP, UDP demux’ed to DHCP.
- The server formulates a DHCP ack containing the client’s IP address, the IP address of the first-hop router, and the name and IP address of the DNS server.
- The reply is encapsulated and forwarded to the client, which demultiplexes it up to DHCP.
- The client now knows its own IP address, the name and IP address of the DNS server, and the IP address of its first-hop router.
DHCP rides on UDP because the client has no address and no connection, so a connectionless transport is the only option. See UDP.
| Hard-coded address | DHCP | |
|---|---|---|
| Who sets it | Sysadmin, in a config file | The network, from a server, when the host joins |
| Reuse | Held whether or not the host is connected | Held only while connected, so the address can be reused |
| Mobile users | Poor fit | Supported, hosts join and leave freely |
In the exam
- Two questions, one answer. DHCP is the host-part answer. Say so if asked what problem it solves.
- Four messages in order: discover, offer, request, ack. Know that discover and offer are the optional ones.
- Beyond the address: first-hop router, DNS server name and address, network mask. A “what else does DHCP return” question wants these three.
- Encapsulation order for the request: DHCP in UDP in IP in Ethernet, sent
as a broadcast to
FFFFFFFFFFFF. - Ports: client
68, server67. The client uses source0.0.0.0because it has no address yet.
Aside
The lecture’s figure for the scenario is partly garbled in the text dump, so
the transaction ID on the request and ack is not quoted here. The four-message
structure, the ports, the address 223.1.2.4 and the 3600 secs lifetime are
all readable.
Check yourself
- DHCP gives a host its host-part address when it joins, and lets it renew and release the lease.
- Messages: discover, offer, request, ack. Discover and offer are optional if the client reuses a remembered address.
- The server is usually in the router and also returns the first-hop router, the DNS server and the network mask.
- The request travels as DHCP in UDP in IP in Ethernet, broadcast to
FFFFFFFFFFFF.