Sub topic 8
DHCP: automatic addressing and reservations
This chapter assumes you know what an IPv4 address, subnet mask, and default gateway are, and that you can open a command prompt. It covers what the Dynamic Host Configuration Protocol (DHCP) does, how a lease works, how to reserve an address for a device, and the errors you will see on the exam and on the job.
What DHCP does
DHCP is a network service that gives IP settings to clients automatically. A client is any device that asks for settings, such as a laptop, phone, or printer. In a SOHO network, the router usually runs the DHCP server. A DHCP server hands out these settings:
- An IP address from a range called a scope or pool
- A subnet mask
- A default gateway, which is the router's LAN address
- DNS server addresses
- A lease time, which is how long the client may keep the address
Without DHCP, you would type these values into every device by hand. That is slow and easy to get wrong, and two devices given the same address will conflict.
The DORA exchange
A client with no address cannot send traffic to a specific server. It uses broadcasts, which are messages sent to every device on the local network. The exchange has four steps, remembered as DORA.
- Discover. The client broadcasts a request for any DHCP server.
- Offer. A server proposes an address and settings.
- Request. The client asks to use the offered address.
- Acknowledge. The server confirms the lease.
DHCP uses UDP. The server listens on port 67 and the client on port 68.
Leases and renewal
An address from DHCP is leased, not owned. When the lease time ends, the address returns to the pool. The client tries to renew at the halfway point of the lease by asking the same server to extend it. If that fails, it tries again later and may broadcast to any server. If the lease expires with no answer, the client loses the address.
A short lease, such as one hour, suits a coffee shop where devices come and go. A long lease, such as a week, suits an office where the same devices stay. Home routers often default to 24 hours.
The scope
The scope defines the range of addresses the server may give out. A typical home router uses a range such as 192.168.1.100 to 192.168.1.199 on the 192.168.1.0/24 network. Three points matter:
- The scope must sit inside the router's subnet.
- The router's own address, such as 192.168.1.1, must be outside the scope.
- A scope that is too small runs out of addresses, and new devices then fail to connect.
Addresses outside the scope, such as 192.168.1.2 to 192.168.1.99 here, are free for static assignment.
Static addresses, dynamic addresses, and reservations
You can assign addresses in three ways.
| Method | How it works | Typical use |
|---|---|---|
| Dynamic (DHCP) | Server picks any free address from the scope | Laptops, phones, tablets |
| Static | You type the address on the device itself | Routers, some servers |
| DHCP reservation | Server always gives one device the same address, matched by its MAC address | Printers, NAS drives, cameras |
A MAC address is the hardware address built into a network adapter. A reservation links one MAC address to one IP address in the router's settings. The device still uses DHCP, so it still receives the gateway and DNS settings, and you manage the address in one place.
Reservations are usually better than static addresses on the device. If you change the router's DNS or gateway later, reserved devices pick up the change at their next renewal. Static devices must be edited one by one.
If you reserve an address inside the scope, the server will not give it to anyone else. If you use a static address inside the scope instead, the server does not know about it and may hand it to another device, which causes an address conflict. Keep static addresses outside the scope.
Viewing and refreshing a lease
Use ipconfig /all on Windows to see the lease details for each adapter:
ipconfig /allLook for "DHCP Enabled", "DHCP Server", "Lease Obtained", and "Lease Expires". An address starting with 169.254 means the client did not get a reply from any DHCP server and assigned itself an APIPA address. APIPA addresses only work on the local link, so the device has no internet access.
To force a new lease, release the current one and request another:
ipconfig /release
ipconfig /renewOn Linux and macOS the commands differ, so the exam focuses on the Windows ones.
Common DHCP problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Address starts with 169.254 | No DHCP server reached | Check the cable or Wi-Fi link, confirm DHCP is enabled on the router, then run `ipconfig /renew` |
| "IP address conflict" message | Two devices share an address, often a static address inside the scope | Move the static address outside the scope or convert it to a reservation |
| New devices cannot join, others work | Scope is exhausted | Enlarge the scope or shorten the lease time |
| Internet works by IP but not by name | DHCP gave a wrong or unreachable DNS server | Check the DNS value in `ipconfig /all` |
| Address is on a different subnet, such as 192.168.0.x instead of 192.168.1.x | A second router or rogue DHCP server is answering | Find and disable the extra DHCP server |
A rogue DHCP server is an unauthorized device that answers client requests. A common case is someone plugging a second home router into the office network with its DHCP server still turned on. Clients may receive a wrong gateway or DNS server, which breaks connectivity and can be used to redirect traffic.
Configuring DHCP on a SOHO router
Most routers have a LAN or DHCP page with these settings:
- Enable or disable the DHCP server.
- Set the starting and ending address of the scope.
- Set the lease time.
- Set the DNS servers to give to clients. The default is usually the router itself, which forwards queries upstream.
- Add reservations by choosing a connected device or entering its MAC address and the IP address you want.
After saving a reservation, release and renew on the device or restart it so it picks up the new address.
Exercise
A small office printer keeps getting a different address, so users' print settings break. The router's DHCP scope is 192.168.1.100 to 192.168.1.199. What is the best fix, and where should the printer's address be chosen from?
Show answer
Create a DHCP reservation on the router that ties the printer's MAC address to a fixed address. The printer keeps getting its other settings automatically. Choose an address that is not in use by another device. It may be inside the scope, because the reservation stops the server from giving it to anyone else. If you set a static address on the printer itself instead, choose one outside the scope, such as 192.168.1.50.
Exercise
A laptop shows the address 169.254.37.12 and cannot reach the internet. Name the cause, then give the command sequence you would try after checking the connection.
Show answer
The laptop could not reach a DHCP server, so it assigned itself an APIPA address. After checking the cable or Wi-Fi connection and that DHCP is enabled on the router, run ipconfig /release and then ipconfig /renew, and confirm the new address with ipconfig /all.