Sub topic 3
DHCP at a Glance: Clients, Servers and Leases
This chapter gives the working model of the Dynamic Host Configuration Protocol (DHCP). It assumes you know IPv4 addresses and subnet masks, what a default gateway and a DNS server do, and what a LAN, a router and a broadcast are. It also assumes you understand client-server communication at a high level.
What DHCP does
DHCP is a protocol that gives a host its network settings automatically when it joins a network. A host needs an IP address, a subnet mask, a default gateway and at least one DNS server before it can talk beyond its own link. Without DHCP, someone types these values into every device by hand. With DHCP, the device asks the network for them and receives them in seconds.
DHCP involves three things:
- Client: the device that needs settings, such as a laptop, phone or printer. The client runs a small DHCP client program, often as part of the operating system's network stack.
- Server: a program that owns a pool of addresses and a set of settings, and hands them out on request. It can run on a router, a Linux host, a Windows Server or a dedicated appliance.
- Lease: a temporary right to use an address. The server records which client holds which address and for how long.
The lease model
The server does not give an address away permanently. It lends the address for a fixed time, called the lease time. When the lease ends, the address returns to the pool unless the client renews it.
Leases solve a practical problem. Devices come and go, and most never announce that they have left. A phone that leaves the Wi-Fi network cannot tell the server to free its address. With leases, the server reclaims the address by itself once the time runs out, so the pool does not fill up with addresses that nobody uses.
The server keeps a table of leases. Each entry holds roughly the following:
| Field | Meaning |
|---|---|
| Client identifier | Usually the client's MAC address, or an ID the client sends |
| IP address | The address lent to that client |
| Lease start | When the lease was granted |
| Lease duration | How long the client may use the address |
| State | Active, expired or reserved |
The lease time is a trade-off. A short lease, such as 1 hour, recovers addresses quickly and suits busy guest networks. It also creates more renewal traffic. A long lease, such as 7 days, reduces traffic and suits stable office networks. It holds addresses longer after a device leaves.
What the client receives
A DHCP server sends more than an address. A typical reply carries:
- An IP address for the client.
- A subnet mask.
- The default gateway (the router).
- One or more DNS servers.
- The lease time.
These extra values are called options. A later chapter covers them in detail.
The big picture
The sequence below shows the overall flow. The next chapters explain each step, the ports and the exact messages.
Common mistakes
- Treating DHCP as address-only. DHCP also delivers the gateway and DNS servers. A client with a valid address but a wrong gateway can reach its own subnet and nothing beyond it.
- Assuming a device keeps the same address. A lease does not promise the same address next time. If a device needs a fixed address, use a reservation, which a later chapter covers.
- Setting leases too long on a small pool. If the pool has 50 addresses and 200 devices visit in a week, a 7-day lease can exhaust it. Shorten the lease or enlarge the pool.
- Running two servers for the same range without planning. Two servers can hand out the same address to different clients. Each server needs its own non-overlapping range, or the servers must be set up as a failover pair.
Exercise
A conference network has a pool of 100 addresses. About 400 different attendees connect over one day, but only 80 are connected at any moment. Would you choose a lease time of 1 hour or 3 days, and why?
Show answer
Choose 1 hour. With a 3-day lease, every attendee who connects holds an address for 3 days even after leaving, so the pool of 100 runs out after about 100 visitors. With a 1-hour lease, departed devices free their addresses quickly, and the 80 devices connected at any moment fit in the pool. The cost is more frequent renewals, which is acceptable here.
Exercise
Name the three roles in DHCP and say what each one does.
Show answer
The client is the device that asks for network settings. The server owns the address pool and the settings and grants them. The lease is the time-limited right the client gets to use an address, which the server records and takes back when it expires.