DHCP Explained: DORA, Leases, Relays and Security
What is DHCP?
DHCP (Dynamic Host Configuration Protocol) automatically gives devices an IP address, subnet mask, default gateway, DNS servers and other settings when they join a network. A client and server exchange four messages, known as DORA, over UDP ports 67 and 68. The address is leased for a set time and renewed while the device stays connected, so administrators do not configure each host by hand.
Why networks use DHCP
Typing addresses into every laptop, phone and printer does not scale and leads to duplicate addresses and typing errors. DHCP, defined in RFC 2131, centralises the settings: change the DNS server once in the DHCP scope and every client picks it up at its next renewal. Static addresses remain the right choice for routers, firewalls and core servers, while everything else usually leases its address.
Key terms
- Scope (or pool): the range of addresses a server may hand out on one subnet, plus the options sent with them.
- Exclusion: addresses inside the subnet that the server must never hand out, such as the gateway and printers.
- Lease: the period for which a client may use an address before renewing it.
- Reservation: a fixed address always given to one client, identified by its MAC address or client identifier.
- Options: extra settings, for example option 3 (router), option 6 (DNS servers) and option 51 (lease time).
The DORA exchange
A new client has no address, so the conversation starts with broadcasts. The server listens on UDP port 67 and the client on UDP port 68.
- Discover: the client broadcasts from
0.0.0.0to255.255.255.255, asking any DHCP server to respond. The message includes its MAC address. - Offer: each server that has a free address replies with an offer containing the address, mask, lease time and options.
- Request: the client picks one offer and broadcasts a request naming that server (option 54, server identifier). The broadcast also tells other servers their offers were declined.
- Acknowledge: the chosen server confirms with a DHCPACK, and the client configures its interface. If the address is no longer available, the server sends a DHCPNAK and the client starts again.
Client (UDP 68) Server (UDP 67)
| --- DHCPDISCOVER 0.0.0.0 -> 255.255.255.255 ---> |
| <-- DHCPOFFER 192.168.10.50, lease 8h ------- |
| --- DHCPREQUEST "I accept 192.168.10.50" -----> |
| <-- DHCPACK mask, gateway, DNS, lease ----- |Many clients also probe the offered address with ARP before using it. If another device answers, the client sends DHCPDECLINE so the server marks the address as in conflict.
Leases, renewal and release
A lease is not permanent. At half the lease time, called T1, the client unicasts a renewal request to the server that gave it the address. If that server does not reply, at 87.5 per cent of the lease (T2) the client broadcasts to any server, a step called rebinding. If the lease expires with no answer, the client must stop using the address.
| Situation | Typical lease choice | Reason |
|---|---|---|
| Office desktops | Several days | Devices stay put; fewer renewals |
| Guest or café Wi-Fi | A few hours | Many short visits; addresses return to the pool quickly |
| Lab or test network | Short, such as one hour | Changes take effect fast while you experiment |
When a device leaves cleanly it can send DHCPRELEASE to hand the address back. When the pool runs out, new clients get no offer and fall back to a 169.254.x.x link-local address, which is the classic symptom described in the IP addressing guide.
Configuring a DHCP server
On a Cisco router or Layer 3 switch, exclude the static addresses first, then define the pool. The lease command takes days, then optional hours and minutes.
ip dhcp excluded-address 192.168.10.1 192.168.10.20
!
ip dhcp pool STAFF
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
dns-server 192.168.10.10
domain-name office.example
lease 1
!
show ip dhcp binding
show ip dhcp poolOn a small Linux server, dnsmasq is a compact option. This configuration serves one range with a 12-hour lease and reserves an address for a printer by MAC address:
# /etc/dnsmasq.conf
interface=eth1
dhcp-range=192.168.50.100,192.168.50.200,255.255.255.0,12h
dhcp-option=option:router,192.168.50.1
dhcp-option=option:dns-server,192.168.50.10
dhcp-host=02:11:22:33:44:55,192.168.50.20,printer DHCP relay: serving many subnets from one server
Routers do not forward broadcasts, so a Discover from VLAN 20 never reaches a server in the data centre VLAN. A DHCP relay agent on the router interface solves this. It receives the broadcast, writes its own interface address into the giaddr field and forwards the message as unicast to the server. The server reads giaddr to pick the right scope, and the relay passes the reply back to the client.
interface Vlan20
ip address 192.168.20.1 255.255.255.0
ip helper-address 10.0.0.10The server needs a scope for 192.168.20.0/24 and a route back to 192.168.20.1. On Cisco devices, ip helper-address also forwards a few other UDP broadcasts by default, such as TFTP and DNS, which you can restrict if needed. VLAN design is covered in VLANs explained.
Rogue DHCP and DHCP snooping
Clients accept the first useful offer, so any device that answers DHCP can hand out a false gateway or DNS server. Sometimes this is an accident, such as a home router plugged in backwards; sometimes it is an attack that sends traffic through an attacker. A related attack, DHCP starvation, floods requests with fake MAC addresses until the pool is empty.
DHCP snooping on managed switches stops both. Ports facing real DHCP servers or uplinks are marked trusted; offers arriving on any other port are dropped, and request rates can be limited.
ip dhcp snooping
ip dhcp snooping vlan 10,20
!
interface GigabitEthernet0/24
description Uplink towards DHCP server
ip dhcp snooping trust
!
interface range GigabitEthernet0/1 - 23
ip dhcp snooping limit rate 15The snooping binding table also feeds Dynamic ARP Inspection and IP Source Guard, which are part of the layered controls in securing a network.
Practical exercise: watch DORA on your own machine
Do this on your own computer and network.
- Start a capture in Wireshark with the display filter
dhcp, or runsudo tcpdump -ni eth0 port 67 or port 68. - On Windows, run
ipconfig /releasethenipconfig /renew. On Linux with NetworkManager, runnmcli connection downandnmcli connection upwith your connection name. - Find the four DORA messages and note the transaction ID, the offered address, the server identifier and the lease time.
- Run
ipconfig /allorip addrand confirm the lease details match the capture.
You are done when you can label each packet and explain why the Request is still a broadcast. Building DHCP pools and relays in a lab is part of the Networking Foundation programme.
Common mistakes
- Forgetting to exclude the gateway and server addresses, so DHCP hands them to clients and causes conflicts.
- Adding a new VLAN without an
ip helper-address, so its clients end up with 169.254 addresses. - Placing reservations inside the dynamic range without excluding them.
- Using very long leases on a busy guest network and exhausting the pool.
- Enabling DHCP snooping without trusting the uplink port, which blocks every legitimate offer.
Frequently asked questions
Which ports does DHCP use?
DHCP for IPv4 uses UDP port 67 on the server and UDP port 68 on the client. DHCPv6 uses UDP 547 for servers and relays and UDP 546 for clients.
Can two DHCP servers share one subnet?
Yes, if their pools do not overlap or they run a failover protocol. Uncoordinated servers with overlapping ranges cause duplicate addresses.
Is DHCP the same as DNS?
No. DHCP assigns addresses and settings, including which DNS servers to use; DNS translates names into addresses. See how DNS works for the second part.
Why did my device get a 169.254 address?
It sent Discover messages and received no usable offer, so it assigned itself a link-local address. Check the cable or Wi-Fi, the VLAN, any relay and whether the pool is full.