Intermediate · IP services: DHCP, DNS, NAT and more · topic 36 of 57 · 30 min
DHCP: automatic addresses
Explanation
Why DHCP?
Every device needs an IP address, a subnet mask, a default gateway and DNS server addresses before it can use the network. Typing these by hand on 500 laptops and phones is slow, and one typo or duplicate address breaks things. DHCP hands them out automatically, keeps track of who has which address, and takes addresses back when devices leave.
Servers, routers, printers and network devices usually keep static (hand-typed) addresses, or a DHCP reservation that always gives the same address to the same MAC. Laptops, phones and desktops use DHCP.
DORA: the four messages
- Discover: the client has no address yet, so it sends a broadcast from 0.0.0.0 to 255.255.255.255: "Is there a DHCP server here?"
- Offer: a server replies with an offer: an IP address, mask, gateway, DNS servers and lease time.
- Request: the client broadcasts "I would like the address that server offered". It is a broadcast so that any other servers that made offers know they were not chosen.
- Acknowledge (ACK): the server confirms. The client now uses the address.
DHCP runs over UDP. The server listens on port 67 and the client uses port 68. Other messages you may see: Release (the client gives the address back), Decline (the client found someone else already using it) and NAK (the server refuses a request, for example after the client moved to another subnet).
Leases and options
An address is lent, not given forever. The lease time says for how long. At half the lease (called T1), the client asks its server directly to renew. If that fails, at 87.5% of the lease (T2) it broadcasts to any server. If the lease runs out, the client must stop using the address.
DHCP options carry the extra settings: the default router (gateway), the DNS servers, the domain name, and many more. Excluded addresses are addresses inside the subnet that the server must never hand out, such as the router's own address, printers and servers.
A Cisco router as DHCP server
R1(config)# ip dhcp excluded-address 192.168.10.1 192.168.10.20
R1(config)# ip dhcp pool LAN10
R1(dhcp-config)# network 192.168.10.0 255.255.255.0
R1(dhcp-config)# default-router 192.168.10.1
R1(dhcp-config)# dns-server 8.8.8.8 1.1.1.1
R1(dhcp-config)# domain-name office.example
R1(dhcp-config)# lease 0 8The excluded-address command is global (not inside the pool). The pool name is just a label. The router hands out addresses from the network that are not excluded and not in use.
R1# show ip dhcp binding
IP address Client-ID/Hardware address Lease expiration Type
192.168.10.21 0100.5079.6668.01 Oct 20 2026 06:12 AM Automatic
192.168.10.22 0100.0c29.3a4b.5c Oct 20 2026 06:15 AM Automatic
R1# show ip dhcp pool
R1# show ip dhcp conflictDHCP relay: ip helper-address
Broadcasts do not cross routers. In a company with ten VLANs, you do not want ten DHCP servers, so one central server serves every subnet. The router interface that faces the clients (their default gateway) is configured with ip helper-address. It catches the client's broadcast, turns it into a unicast to the server, and writes its own interface address into the message (a field called giaddr). The server uses that address to pick the right pool.
R2(config)# interface GigabitEthernet0/0
R2(config-if)# ip address 192.168.20.1 255.255.255.0
R2(config-if)# ip helper-address 10.0.0.5A router interface can also be a DHCP client, which is common on the link to an ISP: interface g0/1, then ip address dhcp.
Troubleshooting and APIPA
When a Windows PC gets no answer from any DHCP server, it gives itself an APIPA address (Automatic Private IP Addressing) from 169.254.0.0/16. It can talk only to other APIPA devices on the same link, not to the gateway or the internet. So an address starting with 169.254 means "DHCP failed", not "the network is fine". On Windows, check with ipconfig /all, and try ipconfig /release then ipconfig /renew.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
DHCP: automatic addresses · 1/8
In this lesson you will learn how devices get their IP settings automatically with DHCP.
Prefer a video by a teacher? Find free videos on “dhcp dora process explained cisco router dhcp server ip helper-address” on YouTube ↗
In real life: College hostel Wi-Fi
An engineering college in Coimbatore has 1,500 students in its hostels, each with a phone and a laptop. Every hostel block is a VLAN, and one central DHCP server serves them all through ip helper-address on the core switch. Because devices come and go all day, the lease is 8 hours, so addresses from students who left are freed quickly. When students complained about "no internet" one evening, the network team saw 169.254 addresses on their laptops and found that the block's pool had run out. They moved that VLAN to a larger subnet.
Practice (0/3 done)
In what order do the four DHCP messages happen?
Simulate a DHCP pool. Write next_free(network, excluded, leased) that returns the first host address of the network (as a string) that is not inside any excluded range and not already leased. excluded is a list of (first, last) address strings, like ip dhcp excluded-address. leased is a set of address strings. Return None when the pool is full. Use the ipaddress module.
Packet Tracer lab. R1 G0/0 is 192.168.10.1/24 (LAN with PC1 and PC2). R1 G0/1 10.0.12.1/30 connects to R2 G0/1 10.0.12.2/30. R2 G0/0 is 192.168.20.1/24 (LAN with PC3). Make R1 the DHCP server for BOTH LANs, with .1 to .10 excluded in each, DNS 8.8.8.8, and use ip helper-address on R2 so PC3 gets an address from R1. Add static routes so the subnets can reach each other.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- DNS: names to addressesIP services: DHCP, DNS, NAT and more · same module
- NAT and PATIP services: DHCP, DNS, NAT and more · same module
- Management services: NTP, SNMP, syslog and TFTPIP services: DHCP, DNS, NAT and more · same module
- Network basics: IP addresses, routes, DNS and the ip commandLinux and Red Hat (RHCSA to RHCE) · Software and networking
- Layer 2 security: port security, DHCP snooping, DAINetwork security
- Clients, servers, IP addresses and URLsBackend Development · How the web and backends work
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which UDP port does a DHCP server listen on?
Answer: 67
The server uses UDP 67 and the client UDP 68. 53 is DNS and 69 is TFTP.
A laptop shows the address 169.254.33.10. What does this tell you?
Answer: It got no reply from a DHCP server
169.254.0.0/16 is APIPA, which Windows uses when DHCP fails.
Where do you configure ip helper-address?
Answer: On the router interface facing the DHCP clients
The relay must be on the interface that receives the clients' broadcasts, which is their default gateway.
Why is the DHCP Request message a broadcast?
Answer: Because the client still has no confirmed address, and all servers should know which offer was chosen
The broadcast tells every server that made an offer which one the client accepted.
Which pool command gives clients their default gateway?
Answer: default-router 192.168.10.1
Inside ip dhcp pool, default-router sets the gateway option.
Users report that connections drop at random, and Windows shows an "IP address conflict" warning. What is the most likely cause?Related
Answer: Two devices have the same IP address
An IP conflict means two devices use the same address, often a static address that is also in the DHCP pool.
Which command shows the default gateway?Related
Answer: ip route
The "default via" line in ip route is the gateway.
From Network basics: IP addresses, routes, DNS and the ip command
With DHCP snooping on, which port should be trusted?Related
Answer: The uplink towards the real DHCP server
Only ports that lead to legitimate DHCP servers (or relays) should be trusted.
A PC shows the address 169.254.12.9. What is the most likely cause?Related
Answer: It could not get an address from a DHCP server
Windows and macOS give themselves an APIPA address from 169.254.0.0/16 when DHCP does not answer.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “IP services: DHCP, DNS, NAT and more” before its exam: DNS: names to addresses, NAT and PAT, Management services: NTP, SNMP, syslog and TFTP, QoS basics: keeping voice and video clear.
- Module 8 exam: IP services · 15 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Network security. 57 topics left in the course before the final exam.