Kurose and Ross, Computer Networking: A Top-Down Approach, section 4.3 (obtaining a host address with DHCP, and network address translation), cross-checked against RFC 2131 (Dynamic Host Configuration Protocol), RFC 2132 (DHCP Options and BOOTP Vendor Extensions), RFC 1918 (Address Allocation for Private Internets) and RFC 3022 (Traditional IP Network Address Translator). Range sizes and lease timers were recomputed in Python.
Draw the four DHCP messages as a timeline from memory, with the address and port on each arrow. Then push one datagram through a NAT table in each direction. Those two drawings cover most questions.
Textbook slides draw the DHCP offer and ACK (acknowledgment) as broadcasts to 255.255.255.255. RFC 2131 also lets a server send them straight to the client, depending on a flag the client sets. For exams, use the broadcast version.
The picture: a hotel desk and a switchboard#
You arrive at a hotel. You do not bring your own room number. The front desk lends you one, plus a key card that stops working on the day you check out. They also tell you where breakfast is and which number to call for help. That is DHCP, the Dynamic Host Configuration Protocol: a network lends a newcomer an address for a set time, and tells it the other things it needs.
Now picture an office with one public phone number. Callers dial that number and a receptionist connects them to the right extension. When staff call out, the person they ring sees only the main number. That is NAT, network address translation: a whole network shares one public address, and a box at the edge keeps track of which inside machine each conversation belongs to.
Vocabulary, before anything uses it#
| Term | What it means |
|---|---|
| DHCP | Dynamic Host Configuration Protocol: lends a host an IP address and other settings when it joins a network. It runs over UDP (User Datagram Protocol). |
| DHCP server | The machine that hands out addresses. In a small network it is usually built into the router. |
| Lease | The length of time a host may keep the address it was given. It must renew before the lease runs out. |
| 0.0.0.0 | Used as a source address by a host that has no address yet. It means “this host, address unknown”. |
| 255.255.255.255 | The limited broadcast address: delivered to every host on the local subnet, and never forwarded by a router. |
| Default gateway | The first-hop router: where a host sends any datagram for a destination outside its own subnet. |
| ISP | Internet service provider: the company that connects an organization or home to the Internet. |
| NAT | Network address translation: a router rewrites addresses and port numbers so that many inside hosts share one public address. |
| Private address | An address from the ranges set aside for internal use. Many networks reuse the same ones, so the public Internet never routes them. |
| Port number | A 16-bit number in the TCP (Transmission Control Protocol) or UDP header that picks out one application process (socket) on a host. |
DHCP in four messages#
A new host does not know the DHCP server’s address, or even its own. So it broadcasts to 255.255.255.255, reaching everyone on its subnet. The client listens on UDP port 68 and the server on UDP port 67.
| Message | From (address, port) | To (address, port) | What it says |
|---|---|---|---|
| 1. Discover | 0.0.0.0, 68 | 255.255.255.255, 67 | “Is there a DHCP server here?” Carries a random transaction ID. |
| 2. Offer | server, 67 | 255.255.255.255, 68 | “You can have this address, for this long.” Same transaction ID. |
| 3. Request | 0.0.0.0, 68 | 255.255.255.255, 67 | “I accept the offer from that server.” Echoes the offered settings. |
| 4. ACK (acknowledgment) | server, 67 | 255.255.255.255, 68 | “Confirmed. It is yours until the lease ends.” |
Remember the order as DORA. The transaction ID tells a client which replies are its own, since every host hears every broadcast.
Why is the request still sent from 0.0.0.0 to everyone? The host does not own the address until the ACK. And if several servers made offers, the broadcast tells the others to take theirs back.
A phone joins a network. Its discover goes from 0.0.0.0 port 68 to 255.255.255.255 port 67 with transaction ID 48210. The server offers 192.168.4.37 for 86,400 seconds, in a field called yiaddr (“your IP address”). The phone broadcasts a request for it. Once the ACK arrives, the phone uses 192.168.4.37 as its source address.
Routers do not forward 255.255.255.255. If the server is on another subnet, a relay agent on the client’s subnet passes the messages on.
What DHCP hands out, and how leases renew#
An address alone is not enough to use the Internet. The ACK also carries these settings, each as a DHCP option:
- Subnet mask, so the host knows which addresses are on its own subnet.
- Default gateway, the router to send everything else to.
- DNS server (Domain Name System), so the host can turn names into addresses.
- Lease time, how long the address is on loan.
A host does not wait for its lease to run out. RFC 2131 suggests it asks the same server to renew at time T1, half the lease, and asks any server at time T2, seven-eighths of the lease. Servers may set other values.
Lease = 86,400 seconds = 24 hours.
T1 = 0.5 × 86,400 = 43,200 s (12 hours): the host sends a request straight to its server to renew.
T2 = 0.875 × 86,400 = 75,600 s (21 hours): if the server has not answered, the host broadcasts to any server.
At 24 hours with no reply, the host must stop using the address.
Where the address blocks come from#
DHCP hands out addresses from a block. So where does the block come from? Each level gets a slice of the level above it.
- IANA, the Internet Assigned Numbers Authority, run under ICANN (the Internet Corporation for Assigned Names and Numbers), holds the whole address space.
- It gives large blocks to five regional Internet registries, one for each part of the world. North America’s is ARIN, the American Registry for Internet Numbers.
- The registries give blocks to ISPs and large organizations.
- An ISP gives a smaller slice to each customer, which assigns addresses to its own interfaces, often with DHCP.
An ISP holds 161.45.64.0/18: 214 = 16,384 addresses. A customer asks for about 1,000. The ISP gives it 161.45.72.0/22: 210 = 1,024 addresses, from 161.45.72.0 to 161.45.75.255. A /18 holds 222−18 = 16 blocks of this size, so the ISP can serve 15 more customers like this one.
Since every customer block sits inside the ISP’s block, one route to 161.45.64.0/18 reaches them all. That is route aggregation, worked through in the guide on longest prefix matching and route aggregation.
NAT: one public address for a whole network#
IPv4 has only about 4.3 billion addresses, and IANA handed out its last free blocks in 2011. NAT stretches them. Inside the network, hosts use private addresses from three ranges set aside by RFC 1918:
| Block | Range | Addresses |
|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 to 10.255.255.255 | 16,777,216 |
| 172.16.0.0/12 | 172.16.0.0 to 172.31.255.255 | 1,048,576 |
| 192.168.0.0/16 | 192.168.0.0 to 192.168.255.255 | 65,536 |
Thousands of networks reuse these addresses, so the public Internet never routes them. The NAT router has a private address inside and one public address outside. To the outside world, the whole network looks like one device.
The translation table
The router keeps a NAT translation table. Each row pairs an outside (address, port) with an inside (address, port). The outside is often labeled the WAN side (wide area network) and the inside the LAN side (local area network).
- Going out, it replaces the source address and source port with its public address and a new port, and adds a row.
- Coming back, it looks up the destination port, and replaces the destination address and port with the inside ones from that row.
Both changes alter the headers, so the router also recomputes the IP header checksum and the TCP or UDP checksum.
A design studio uses 10.0.0.0/24 inside. The NAT router’s public address is 203.0.113.9. Two laptops both happen to pick source port 51000 to reach the same web server, 198.51.100.80 port 443.
Out: 10.0.0.11:51000 → 198.51.100.80:443 leaves as 203.0.113.9:40001 → 198.51.100.80:443.
Out: 10.0.0.12:51000 → 198.51.100.80:443 leaves as 203.0.113.9:40002 → 198.51.100.80:443.
Back: 198.51.100.80:443 → 203.0.113.9:40002 arrives. The table says 40002 means 10.0.0.12:51000, so it is delivered as 198.51.100.80:443 → 10.0.0.12:51000.
Without different outside ports, the two replies would look identical: that is why NAT rewrites ports too.
| WAN side (outside) | LAN side (inside) |
|---|---|
| 203.0.113.9, 40001 | 10.0.0.11, 51000 |
| 203.0.113.9, 40002 | 10.0.0.12, 51000 |
How many conversations can one public address hold? The port field is 16 bits, so there are 216 = 65,536 ports. Leaving out the 1,024 well-known ports (0 to 1023) leaves 64,512, which is where the usual “over 60,000 simultaneous connections per public address” figure comes from. Real NATs stretch it by reusing ports across destinations.
Why NAT is controversial#
NAT is everywhere, but draws three objections.
- It breaks layering. A router is a network-layer device, but NAT reads and changes port numbers, which belong to the transport layer.
- It breaks the end-to-end idea. Hosts were meant to reach each other directly. Behind NAT, an outside host cannot start a conversation with an inside one, because no table row exists until the inside host sends first.
- Servers need workarounds. To run a server inside, an administrator sets up port forwarding: a fixed row such as “outside port 8443 always goes to 10.0.0.20 port 443”. Peer-to-peer apps need NAT traversal tricks, such as a relay server.
The long-term answer is IPv6 (Internet Protocol version 6), whose address space is big enough that every device can have a public address. NAT was meant as a stopgap.
DHCP lends a host an address, mask, gateway and DNS server in four broadcast messages (discover, offer, request, ACK) over UDP ports 67 and 68; NAT lets a whole private network share one public address by rewriting source address and port on the way out, and reversing it on the way back using its translation table.
Practice#
For the DHCP questions, draw the four arrows first. For the NAT questions, draw the table first.
- A laptop sends a DHCP discover. Give its source IP address, destination IP address, source UDP port and destination UDP port.
- By the time it sends a DHCP request, the laptop has been offered an address. Why is the request still sent from 0.0.0.0 to 255.255.255.255?
- A DHCP server grants a lease of 2 hours and the client uses the RFC 2131 suggested timers. When does the client first try to renew with its own server, and when does it start asking any server?
- Which of these are RFC 1918 private addresses? 172.15.0.1, 172.31.200.4, 10.255.0.9, 192.169.0.1.
- Using the studio’s NAT table above, a third laptop, 10.0.0.13, sends from port 49152 to 192.0.2.25 port 80, and the router picks outside port 40003. Write the datagram’s source and destination as it leaves the router, and the reply as it arrives and as it is delivered inside.
- A datagram arrives at 203.0.113.9 port 40777, and the table has no row for 40777. What does the router do, and why?
- Roughly how many simultaneous connections can one public IPv4 address support through NAT? Show where the number comes from.
Solutions#
Find the first line where your working split from the solution, and redo the problem from that line. Do not just read the answer and nod.
- Source 0.0.0.0 port 68; destination 255.255.255.255 port 67. The laptop has no address yet and does not know the server’s, so it broadcasts. Clients use port 68 and servers port 67.
- The laptop does not own the address until the ACK arrives, and other servers must hear the choice. More than one server may have offered an address; the broadcast request tells them all which offer was accepted, so the others can release theirs.
- T1 = 60 minutes; T2 = 105 minutes. The lease is 7,200 s. T1 = 0.5 × 7,200 = 3,600 s = 60 min. T2 = 0.875 × 7,200 = 6,300 s = 105 min.
- 172.31.200.4 and 10.255.0.9. 172.16.0.0/12 runs from 172.16.0.0 to 172.31.255.255, so 172.15.0.1 is outside it. 10.0.0.0/8 covers all of 10.x.x.x. 192.169.0.1 is outside 192.168.0.0/16.
- Leaving: 203.0.113.9:40003 → 192.0.2.25:80. Reply arriving: 192.0.2.25:80 → 203.0.113.9:40003. Delivered inside: 192.0.2.25:80 → 10.0.0.13:49152. The router adds the row (203.0.113.9, 40003) ↔ (10.0.0.13, 49152) and uses it in reverse for the reply.
- It drops the datagram (unless a port-forwarding rule covers port 40777). With no row, it has no idea which inside host the datagram is for. This is also why outside hosts cannot start conversations with hosts behind NAT.
- About 60,000. The port field is 16 bits: 216 = 65,536 ports. Leaving out the 1,024 well-known ports gives 64,512. In the simple model, each active connection needs its own outside port on that address.
Test-readiness checklist#
- ☐ I can list the four DHCP messages in order, with source and destination address and port for each.
- ☐ I can explain why DHCP uses 0.0.0.0 and 255.255.255.255, and what the transaction ID is for.
- ☐ I can name four things DHCP hands out, and compute the renewal times for a given lease.
- ☐ I can trace an address block from IANA to a regional registry to an ISP to an organization.
- ☐ I can list the three RFC 1918 private ranges and say whether an address is in one.
- ☐ I can push a datagram through a NAT table in both directions, rewriting addresses and ports.
- ☐ I can explain the 60,000-connection limit and the three main objections to NAT.
In any NAT question, outgoing traffic has its source rewritten and incoming traffic has its destination rewritten. If you find yourself changing the destination of an outgoing datagram, start again.
Frequently asked questions#
What are the four DHCP messages?
Discover, offer, request and acknowledge, often remembered as DORA. The client broadcasts a discover, servers reply with offers, the client broadcasts a request accepting one offer, and that server confirms with an ACK.
Which ports does DHCP use?
DHCP runs over UDP. The server listens on port 67 and the client on port 68.
What does DHCP give a host besides an IP address?
It usually gives the subnet mask, the default gateway (the first-hop router), the address of a DNS server, and the lease time saying how long the address may be kept.
What are the private IP address ranges?
RFC 1918 sets aside 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 to 172.31.255.255) and 192.168.0.0/16. They are reused inside many networks and are not routed on the public Internet.
Why does NAT change port numbers?
Many inside hosts share one public address, so the address alone cannot say which host a reply is for. The NAT router gives each outgoing connection its own outside port and records it in a translation table, so replies reach the right inside host and port.
Something here not clear? A topic you wish we covered? Tell us. We read every message, and a request is the fastest way to get a guide written.
Test yourself on this topic
The free networking practice app has 10 questions on this guide and 500 across the whole course, each with an explanation for every answer. Offline, no ads, no account.
Practise this topic →