Address Configuration and Translation: DHCP and NAT
Dynamic Host Configuration Protocol (DHCP)
A host's IP address can be configured manually by a system administrator, but it is more commonly obtained automatically with the Dynamic Host Configuration Protocol (DHCP). DHCP makes joining a network "plug and play." Besides an IP address, it tells the host its subnet mask, the address of its default gateway (first-hop router), and the address of its local DNS server. A DHCP address comes with a lease time; it must be renewed before the lease expires or it is reclaimed for other hosts.
DHCP is a client-server protocol that runs over UDP: clients use port 68 and servers use port 67. A new host obtains an address in four steps:
| Step | Message | Source address:port | Destination address:port | Purpose |
|---|---|---|---|---|
| 1 | DHCP discover | 0.0.0.0:68 | 255.255.255.255:67 | The new host looks for a DHCP server |
| 2 | DHCP offer | server address:67 | 255.255.255.255:68 | A server proposes an address and lease |
| 3 | DHCP request | 0.0.0.0:68 | 255.255.255.255:67 | The client picks one offer and asks to use it |
| 4 | DHCP ACK | server address:67 | 255.255.255.255:68 | The server confirms; the client starts using the address |
At first the new host has no address of its own and does not know any server's address, so the discover message has source address 0.0.0.0 and the limited-broadcast destination 255.255.255.255. There may be several DHCP servers on the LAN, and each may reply with an offer. The client echoes the offer it chose in its request, which it still broadcasts so that every server learns the choice and unchosen servers can reclaim the addresses they held in reserve.
When half the lease has passed ( lease), the client unicasts a renewal request directly to its server. If no answer arrives by lease, it broadcasts the request so that any server can extend the lease. If the lease expires with no answer, the client must stop using the address and start over with a discover message.
Join a LAN with DHCP: discover, offer, request, ACK
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Network Address Translation (NAT)
Section 4.3 showed that the private ranges 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 are used only inside local networks and cannot appear on the public Internet. Yet hosts in homes and enterprises clearly need Internet access. Network Address Translation (NAT) solves this. A NAT router has a single public address on its Internet-facing side, while the inside network uses private addresses. To the outside world, the whole inside network looks like a single device with a single IP address.
The NAT router maintains a NAT translation table. Each entry associates one public port number with one inside (IP address, port number) pair:
- Inside host 10.0.0.1 sends a datagram from source port 3345 to the web server 128.119.40.186:80.
- The NAT router picks an unused port number, 5001, rewrites the source address and port to 138.76.29.7:5001, and records 5001 ↔ 10.0.0.1:3345 in its translation table.
- The web server sees only 138.76.29.7:5001, so its reply is addressed to 138.76.29.7:5001.
- When the reply reaches the NAT router, the router looks up destination port 5001 in the table, rewrites the destination address and port back to 10.0.0.1:3345, and forwards it to the inside host.
| WAN side | LAN side |
|---|---|
| 138.76.29.7:5001 | 10.0.0.1:3345 |
The port-number field is 16 bits long, so a single public address can support more than 60,000 simultaneous connections.
NAT has costs. Translation entries are created only when inside hosts open connections outward, so outside hosts cannot initiate connections to servers inside unless a static entry such as port forwarding is configured on the NAT. Port numbers are meant to identify processes, not hosts, and a router rewriting them violates the layering principle that the network layer should process only up to the network-layer header. It also complicates applications such as P2P that need direct connections, which require NAT traversal techniques. In the long run, the address shortage should be solved by IPv6 (see Section 4.7).
Watch NAT rewrite addresses and ports
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Trace NAT translations for three connections
A NAT router has public address 138.76.29.7 and allocates public ports from 5001 upward. In order: (1) 10.0.0.1:3345 connects to 128.119.40.186:80; (2) 10.0.0.2:3345 connects to the same server; (3) 10.0.0.1:3346 connects to 203.0.113.50:443; (4) a reply arrives from 128.119.40.186:80 to 138.76.29.7:5002. Give the translation table, the source and destination of each datagram before and after NAT, and how many connections one public address can support.
Plan a DHCP lease timeline
At 08:00:00 a laptop receives DHCP ACK for 192.168.1.23 with a 3600 s lease. Using the default renewal time T1 = 0.5 × lease and rebinding time T2 = 0.875 × lease, give the clock times of T1, T2, and expiry. What is the new expiry if renewal at T1 succeeds? What happens at T2 and at expiry if the server has crashed?