DHCP
Explain the DORA exchange and what options a client receives with its lease.
By Invicly Tech, , in Computer Networking. About 11 minutes to read.
In short
DHCP gives hosts their network configuration automatically: IP address, subnet mask, default gateway, DNS servers and lease time. A new client broadcasts because it has no address yet, and the exchange of four messages is remembered as DORA. Relays forward the broadcasts to a DHCP server on another subnet.
Explained simply
When you plug in a laptop or join Wi-Fi, it needs an IP address, the address of the router (the default gateway), and the address of a DNS server. Typing these by hand on every device would be slow and full of mistakes. DHCP (Dynamic Host Configuration Protocol) hands them out automatically.
A new device has no address yet, so it cannot send a normal letter. Instead it shouts to everyone on the local network: is there a DHCP server here? A server answers with an offer, the device says yes please, and the server confirms. These four steps are called DORA: Discover, Offer, Request, Acknowledge.
The address is not given forever. It is lent for a time called the lease, for example 8 hours or 1 day. Halfway through, the device quietly asks to keep it longer. If a device leaves and never comes back, its address returns to the pool for someone else.
Some devices, like printers and servers, should always get the same address. A reservation ties one address to one device's MAC address (its hardware ID), so you still get central control without typing settings on each device.
Press Play on a diagram to walk through it one step at a time.
- Client (no IP) to DHCP server: DISCOVER (broadcast from 0.0.0.0)1DISCOVER (broadcast from 0.0.0.0)
- DHCP server to Client (no IP): OFFER 10.0.10.50, lease 24h2OFFER 10.0.10.50, lease 24h
- Client (no IP) to DHCP server: REQUEST 10.0.10.50 (broadcast)3REQUEST 10.0.10.50 (broadcast)
- DHCP server to Client (no IP): ACK with mask, gateway, DNS4ACK with mask, gateway, DNS
- Client (no IP) to DHCP server: At 50% of the lease: unicast REQUEST to renew5At 50% of the lease: unicast REQUEST to renew
- Scopes (pools)
- One per subnet
- Start and end address
- Excluded ranges
- Options
- 3 router
- 6 DNS servers
- 15 domain name
- 51 lease time
- Reservations
- MAC address to fixed IP
- Printers, servers, APs
- Leases table
- Who has which address
- When each lease expires
In depth
Why the first messages are broadcasts
A client starting from nothing sends DHCPDISCOVER from source address 0.0.0.0, UDP port 68, to the broadcast address 255.255.255.255, UDP port 67. Every device on the local network receives it, but only DHCP servers reply. The client then broadcasts DHCPREQUEST, even though it already knows the server, for a clever reason: there may be several servers that each made an offer. The broadcast request names the chosen server (option 54, server identifier), so the others learn their offer was declined and put their address back in the pool.
After the ACK, a careful client checks that nobody else already uses the address, by sending ARP probes for it. If someone answers, the client sends DHCPDECLINE and starts again. A server sends DHCPNAK if the client asks for an address that is wrong for its subnet, for example after moving the laptop to another office.
- DHCPDISCOVER, DHCPOFFER, DHCPREQUEST, DHCPACK: the normal four
- DHCPNAK: server says no, start over
- DHCPDECLINE: client found the address already in use
- DHCPRELEASE: client gives the address back early
- DHCPINFORM: client has an address and only wants options
Lease timers: renewing and rebinding
Two timers run inside the lease. At T1, by default 50% of the lease, the client sends a unicast DHCPREQUEST straight to the server that gave it the address. If the server answers with an ACK, the lease starts again from the full length and the user notices nothing.
If that server is down, the client keeps trying until T2, by default 87.5% of the lease. Then it switches to rebinding: it broadcasts the request so that any DHCP server can extend the lease. If the lease runs out with no answer at all, the client must stop using the address, and the network breaks for that device.
Short leases (one hour) suit busy guest Wi-Fi where devices come and go. Long leases (one day or more) suit offices with stable desktops and reduce DHCP traffic.
- 1Bound
ACK received, address in use
- 2T1 at 50%
Unicast REQUEST to the same server
- 3T2 at 87.5%
Broadcast REQUEST to any server
- 4Lease expires
Stop using the address
- 5Start over
Send a new DHCPDISCOVER
The options a client receives
Everything beyond the address itself travels as numbered options. The common ones: 1 subnet mask, 3 router (default gateway), 6 DNS servers, 15 domain name, 42 NTP servers, 51 lease time, 53 the DHCP message type, and 54 the server identifier. Option 43 carries vendor data, often used by wireless access points to find their controller. Options 66 and 67 (TFTP server and boot file name) let machines boot from the network with PXE. Option 121 pushes extra static routes.
The client tells the server which options it wants with option 55 (parameter request list). If a laptop gets an address but cannot reach the internet, check options 3 and 6 first; a wrong gateway or DNS server is the usual mistake.
Relays: one server for many VLANs
Broadcasts stop at routers, so a client in VLAN 20 cannot reach a server in VLAN 10 directly. A DHCP relay agent, usually the router or layer 3 switch that is the VLAN's gateway, listens for those broadcasts. It writes its own interface address on that VLAN into the giaddr (gateway IP address) field and forwards the message as unicast to the server's UDP port 67.
The server reads giaddr to choose the right pool: giaddr 10.0.20.1 means the client lives in 10.0.20.0/24. It sends the reply back to the relay, which passes it to the client on the VLAN. Relays can also add option 82 (relay agent information), naming the switch port, which some networks use for tracking or policy. On Cisco IOS, the command is ip helper-address on the VLAN interface.
- Client in VLAN 20 to Router (relay): DISCOVER broadcast1DISCOVER broadcast
- Router (relay) to DHCP server: Unicast DISCOVER, giaddr 10.0.20.12Unicast DISCOVER, giaddr 10.0.20.1
- DHCP server to Router (relay): OFFER from the 10.0.20.0/24 pool3OFFER from the 10.0.20.0/24 pool
- Router (relay) to Client in VLAN 20: OFFER delivered on VLAN 204OFFER delivered on VLAN 20
- Client in VLAN 20 to Router (relay): REQUEST broadcast5REQUEST broadcast
- Router (relay) to DHCP server: Relayed REQUEST6Relayed REQUEST
- DHCP server to Router (relay): ACK7ACK
- Router (relay) to Client in VLAN 20: ACK: client is configured8ACK: client is configured
Rogue servers, starvation and IPv6
DHCP has no built-in authentication, so any device can pretend to be a server. A rogue server (often a home router plugged in backwards) hands out a wrong gateway, and users lose the network or, worse, send traffic through an attacker. Switches defend with DHCP snooping: only trusted ports, the uplinks to the real server, may send OFFER and ACK messages. A starvation attack requests every address with fake MAC addresses until the pool is empty; port security limits how many MACs one port may use.
IPv6 works differently. Many networks use SLAAC, where hosts build their own address from router advertisements. DHCPv6 uses UDP ports 546 (client) and 547 (server) and the messages SOLICIT, ADVERTISE, REQUEST and REPLY. It can hand out addresses or just DNS settings.
Learn it in 4 short steps
About 25m each. Track them with a timer in your plan.
- 1Trace discover, offer, request, acknowledge~25m
- 2List common DHCP options~25m
- 3Explain leases and renewal~25m
- 4Configure a DHCP relay~25m
Key points
- DHCP uses UDP ports 67 (server) and 68 (client).
- Broadcasts do not cross routers; configure a relay (ip helper-address).
- Reservations give a device the same address based on its MAC.
- Rogue DHCP servers can hijack clients; switches block them with DHCP snooping.
Key terms
Tap a card to flip it. 0/4 known
Examples
! Cisco IOS DHCP pool
ip dhcp excluded-address 10.0.10.1 10.0.10.9
ip dhcp pool STAFF
network 10.0.10.0 255.255.255.0
default-router 10.0.10.1
dns-server 10.0.10.5
! On the remote VLAN interface
interface vlan 20
ip helper-address 10.0.10.5A small DHCP server with dnsmasq
A lab network 10.0.10.0/24 needs addresses from .50 to .200, the router at .1 and a DNS server at .5. The printer must always be .20. Step 1: write the config. Step 2: restart dnsmasq. Step 3: renew a client and check that the leases file shows it. dhcp-range sets the pool and lease time, dhcp-option sets the gateway and DNS, and dhcp-host makes the reservation.
# /etc/dnsmasq.d/lab.conf
interface=eth1
dhcp-range=10.0.10.50,10.0.10.200,255.255.255.0,12h
dhcp-option=option:router,10.0.10.1
dhcp-option=option:dns-server,10.0.10.5
dhcp-host=aa:bb:cc:dd:ee:20,printer,10.0.10.20
# then:
# sudo systemctl restart dnsmasq
# cat /var/lib/misc/dnsmasq.leasesA laptop gets 169.254.x.x
A user in VLAN 30 reports an address like 169.254.12.7. That is a link-local address the OS picks itself when no DHCP server answers. Step 1: on the router, check that VLAN 30's interface has ip helper-address pointing to the server. Step 2: on the server, check that a scope for 10.0.30.0/24 exists; without it, the server ignores requests whose giaddr is 10.0.30.1. Step 3: capture on the client side to see if DISCOVER goes out and whether any OFFER comes back.
# On the client (Linux):
sudo tcpdump -ni eth0 -v 'udp port 67 or udp port 68'
# DISCOVER repeats with no OFFER -> relay or scope problem
# Force a fresh lease once it is fixed:
sudo dhclient -r eth0 && sudo dhclient -v eth0
# Windows: ipconfig /release then ipconfig /renewQuick reference
- DHCP: server UDP 67, client UDP 68; DHCPv6: client 546, server 547
- DORA: DISCOVER, OFFER, REQUEST, ACK; NAK means start over
- Renew at T1 (50% of lease, unicast); rebind at T2 (87.5%, broadcast)
- Option 3 = router, 6 = DNS, 15 = domain name, 51 = lease time, 82 = relay info
- 169.254.x.x on a client means no DHCP server answered
- Cisco relay: ip helper-address followed by the server IP, on the client VLAN interface
- DHCP snooping: mark only the uplink to the real server as trusted
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Find out what your own machine received from DHCP: address, gateway, DNS servers and lease time.
- Exercise 2medium
Capture a full DORA exchange and identify the message type, offered address and router option in each packet.
- Exercise 3hard
Users in a new VLAN 40 (10.0.40.0/24) get no address. The server is 10.0.10.5. List what must exist on the router and the server, and how you would prove each part works.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What happens if two DHCP servers are on the same network?
- Clients take whichever offer arrives first, so they may get the wrong gateway or overlapping addresses. Use one server, or two servers configured for failover with split or shared pools.
- Should servers use DHCP or static addresses?
- Infrastructure that others depend on, such as DNS servers and routers, is usually static. Other servers often use DHCP reservations, which keep the address fixed while staying centrally managed.
- What does a 169.254 address mean?
- It is an automatic link-local address the device chose because no DHCP server answered. Check the cable or Wi-Fi, the relay and the server's scope.