Skip to content

Intermediate · IP services: DHCP, DNS, NAT and more · topic 36 of 57 · 30 min

DHCP: automatic addresses

Explanation

DHCP (Dynamic Host Configuration Protocol) gives a device its IP address, mask, default gateway and DNS servers automatically when it joins a network. It works in four steps: Discover, Offer, Request, Acknowledge (DORA). A Cisco router can be the DHCP server, and ip helper-address relays requests to a server on another subnet.

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.

Think of it like this: DHCP is like the front desk of a hotel. A guest arrives without a room. The desk gives them a room number (the IP address) for a fixed number of nights (the lease), plus the Wi-Fi password and the breakfast timing (the options). When the guest checks out, the room goes back to the pool for the next guest.

DORA: the four messages

  1. 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?"
  2. Offer: a server replies with an offer: an IP address, mask, gateway, DNS servers and lease time.
  3. 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.
  4. 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

output
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 8
Cisco IOS: .1 to .20 are kept for the router, printers and servers. lease 0 8 means 0 days 8 hours; the default lease is 1 day.

The 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.

output
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 conflict
Cisco IOS: bindings show which client has which address. A conflict means an address was found already in use.

DHCP 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.

output
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.5
Cisco IOS: clients on 192.168.20.0/24 get their addresses from the server at 10.0.0.5. The server also needs a pool for 192.168.20.0/24 and a route back.

A 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.

Careful: Common mistakes: (1) forgetting to exclude the gateway and server addresses, so DHCP hands out an address that is already used; (2) a wrong default-router in the pool, so clients get an address but cannot leave the subnet; (3) the helper-address on the wrong interface: it must be on the interface facing the clients; (4) a pool that is too small, or a long lease on a busy guest Wi-Fi, so the pool runs out; (5) no route on the server back to the client subnet.

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

DHCP

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)

Task 1 · Question

In what order do the four DHCP messages happen?

Task 2 · Code · Python

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.

Task 3 · Practice

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

Question 1

1.Which UDP port does a DHCP server listen on?

Question 2

2.A laptop shows the address 169.254.33.10. What does this tell you?

Question 3

3.Where do you configure ip helper-address?

Question 4

4.Why is the DHCP Request message a broadcast?

Question 5

5.Which pool command gives clients their default gateway?

Read more (free)

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.

From Validating addresses and checking the same subnet

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.

From Layer 2 security: port security, DHCP snooping, DAI

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.

From IPv4 address structure and special ranges

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

  1. 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.
  2. Module 8 exam: IP services · 15 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Network security. 57 topics left in the course before the final exam.

← Previous: First hop redundancy: HSRP, VRRP and GLBP