Sub topic 7
DHCP and APIPA
This chapter assumes you know what an IPv4 address, subnet mask and default gateway are, and that you can use the Windows command prompt. You should also know that UDP is a connectionless transport protocol. By the end you will be able to explain how a client gets an address automatically, how to set up reservations and scopes, and how to recognize and fix a client that has fallen back to an APIPA address.
What DHCP Does
Dynamic Host Configuration Protocol (DHCP) is a service that hands out network settings to clients automatically. Without it, an administrator would have to type an address, mask, gateway and DNS server into every device by hand. A typo or a duplicate address would then break connectivity.
A DHCP server usually supplies these settings:
- IPv4 address
- Subnet mask
- Default gateway
- DNS server addresses
- Lease time, which is how long the client may keep the address
In a small office or home, the DHCP server is normally built into the router. In larger networks it is a separate server, such as a Windows Server or Linux machine. A router can also relay requests to a central server in another subnet. This is called a DHCP relay or IP helper.
DHCP uses UDP. The server listens on port 67 and the client uses port 68.
The DORA Process
A client with no address cannot send a normal unicast packet. It therefore starts with broadcasts. The exchange has four steps, remembered as DORA.
- Discover. The client broadcasts a request asking whether any DHCP server is available.
- Offer. A server replies with a proposed address and settings.
- Request. The client broadcasts that it accepts a specific offer. Because this is a broadcast, other servers learn their offers were declined.
- Acknowledge. The server confirms the lease and records it.
Broadcasts do not cross routers. This is why a client in a remote subnet needs a relay agent to reach a central DHCP server.
Leases and Renewal
An address from DHCP is leased, not owned. The lease has a duration, such as 8 hours for a guest network or several days for an office network. The client tries to renew at about half of the lease time by contacting the same server. If that fails, it tries again later and may broadcast to any server. If the lease expires with no renewal, the client must give up the address and start over.
Short leases suit networks where devices come and go, such as a coffee shop. Long leases suit stable networks, because there is less renewal traffic and fewer surprises if the server is briefly offline.
Scopes, Exclusions and Reservations
A scope is the range of addresses a DHCP server may give out, plus the settings that go with it. For example, a scope might cover 192.168.1.100 to 192.168.1.199 with mask 255.255.255.0 and gateway 192.168.1.1.
Two features control which addresses in the network are handed out:
- Exclusion: an address or range inside the scope that the server must never lease. Use it for devices with manually set (static) addresses, so the server does not give the same address to someone else.
- Reservation: a rule that always gives one specific device the same address. The server identifies the device by its MAC address.
A reservation is different from a static address. With a static address, you configure the device itself. With a reservation, the device still asks for DHCP, but the server always answers with the same address. Reservations keep the settings in one place. They suit printers, file servers and security cameras, which other devices need to find at a fixed address.
| Method | Where it is configured | Changes if the device is replaced? | Typical use |
|---|---|---|---|
| Dynamic lease | DHCP server | Yes, new address likely | Laptops, phones |
| Reservation | DHCP server, tied to MAC address | Yes, because the MAC changes | Printers, servers |
| Static address | On the device | No, but you must reconfigure it | Routers, infrastructure |
If you use static addresses, pick them outside the DHCP scope or add an exclusion. Otherwise two devices can end up with the same address, which causes an IP conflict. Windows then shows a message that another system has the same address.
What Is APIPA
Automatic Private IP Addressing (APIPA) is a Windows fallback. When a client is set to obtain its address automatically and gets no answer from a DHCP server, it assigns itself an address in the range 169.254.0.1 to 169.254.255.254, with mask 255.255.0.0. The client first checks that no one else is using the chosen address. Other operating systems use the same idea and call it link-local addressing.
APIPA gives a client just enough to talk to other devices on the same local segment that also have 169.254.x.x addresses. It provides no default gateway and no DNS server. A client with an APIPA address therefore cannot reach the internet or other subnets.
The client does not give up after self-assigning. It keeps checking for a DHCP server in the background. When a server becomes available, the client takes a proper lease.
Diagnosing an APIPA Address
The most common sign is a user who can see the network icon connected but cannot open any website. Run ipconfig /all and read the address.
ipconfig /allLook for these fields on the adapter:
- IPv4 Address starting with 169.254 means the client did not get a lease.
- DHCP Enabled should say Yes. If it says No, the adapter has a static configuration.
- DHCP Server shows which server answered. For an APIPA address it is blank.
- Lease Obtained and Lease Expires show the lease times for a valid lease.
Common causes of a failed lease are:
- The DHCP server or router is off, crashed or out of memory.
- The scope has no free addresses left, so the server has nothing to offer.
- A cable is loose, a switch port is bad, or the wireless client is on the wrong network.
- A VLAN or a firewall blocks the broadcasts, or no relay is configured for a remote subnet.
- A rogue DHCP server, such as a home router plugged into the office network, is handing out wrong settings.
Check the physical link first, then try to get a new lease:
ipconfig /release
ipconfig /renew
ipconfig /flushdnsipconfig /release drops the current lease. ipconfig /renew sends a new DORA request. ipconfig /flushdns clears the DNS resolver cache and is useful after the address and DNS servers change. If /renew still returns an APIPA address, check the server, the scope and the network path.
Rogue DHCP Servers and Wrong Settings
Sometimes a client has an address that is not APIPA but is still wrong. For example, it may be in 192.168.0.x while the office uses 10.0.0.x. This usually means an unauthorized device, often a small router connected by its LAN port, answered the Discover first. Compare the DHCP Server field in ipconfig /all with the address of your real server. Remove the rogue device, then release and renew.
Quick Reference
| Item | Value |
|---|---|
| DHCP server port | UDP 67 |
| DHCP client port | UDP 68 |
| Process | Discover, Offer, Request, Acknowledge |
| APIPA range | 169.254.0.1 to 169.254.255.254 |
| APIPA mask | 255.255.0.0 |
| APIPA gateway | None |
Exercise
A user's laptop shows the address 169.254.37.12 and cannot browse the internet. A coworker on the same switch works normally. List two steps you would take, in order, and explain what each tells you.
Show answer
First, check the physical connection (cable, switch port or wireless network) and run ipconfig /all to confirm that DHCP Enabled is Yes and the DHCP Server field is blank. Then run ipconfig /release and ipconfig /renew. If the laptop now gets a normal address, the first attempt just missed the server. If it stays on 169.254.x.x while the coworker is fine, the problem is specific to this laptop's link or port, so try another cable or port. If other new clients also fail, check the DHCP server or router and whether its scope is full.
Exercise
A network printer must always be at 192.168.1.50, and the office uses DHCP with a scope of 192.168.1.100 to 192.168.1.199. Name two ways to do this and say which is easier to manage centrally.
Show answer
You can set a static address on the printer (192.168.1.50 is outside the scope, so no conflict arises), or create a DHCP reservation that ties 192.168.1.50 to the printer's MAC address. The reservation is easier to manage centrally, because the address and other settings, such as the gateway, stay on the server. If the address is inside the scope range, a reservation is the safer choice.