How DHCP works: Discover, Offer, Request, Acknowledge

Why DHCP?

Typing addresses into hundreds of PCs is slow and mistakes are easy. With DHCP (Dynamic Host Configuration Protocol) a PC asks for its settings when it connects, and a server hands out an address from a pool for a limited time: a lease.

DORA

#MessageFrom → toSays
1DISCOVERClient → broadcast 255.255.255.255"Is there a DHCP server?" (the client has no address yet: source 0.0.0.0)
2OFFERServer → client"You can have 192.168.10.10, mask /24, gateway .1, DNS .5, for one day"
3REQUESTClient → broadcast"I'll take 192.168.10.10 from that server" (broadcast, so other servers know their offers weren't taken)
4ACKServer → client"It's yours." The client starts using the address

DHCP uses UDP: servers listen on port 67, clients on port 68. Before offering an address, a Cisco server pings it, and a client checks it with ARP, so an address someone typed in by hand isn't handed out twice.

Below, PC1 asks for a new lease (Windows ipconfig /renew) and the router shows who has which address. Turn on Packet Walk in the Try-it panel and renew again to watch the four messages.

In NetLab

▶ PC1
NetLab Windows-style command prompt. Type help to see the commands.
C:\Users\student>ipconfig /release

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::11db:99de:fbce:36d1%12
   Default Gateway . . . . . . . . . : 
C:\Users\student>ipconfig /renew

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : corp.local
   Link-local IPv6 Address . . . . . : fe80::11db:99de:fbce:36d1%12
   IPv4 Address. . . . . . . . . . . : 192.168.10.10
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.10.1
C:\Users\student>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : PC1
   Primary Dns Suffix  . . . . . . . : 
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : corp.local
   Description . . . . . . . . . . . : NetLab Gigabit Network Adapter
   Physical Address. . . . . . . . . : 00-1A-33-D5-62-B1
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::11db:99de:fbce:36d1%12(Preferred) 
   IPv4 Address. . . . . . . . . . . : 192.168.10.10(Preferred) 
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Monday, March 1, 1993 12:00:02 AM
   Lease Expires . . . . . . . . . . : Tuesday, March 2, 1993 12:00:02 AM
   Default Gateway . . . . . . . . . : 192.168.10.1
   DHCP Server . . . . . . . . . . . : 192.168.10.1
   DNS Servers . . . . . . . . . . . : 192.168.10.5
▶ R1
R1>enable
R1#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address          Client-ID/              Lease expiration        Type
                    Hardware address/
                    User name
192.168.10.10       0100.1a33.d562.b1       Mar 02 1993 12:00 AM    Automatic
192.168.10.11       0100.1af2.3aa4.ee       Mar 02 1993 12:00 AM    Automatic

Leases and renewal

  • At 50% of the lease (T1) the client asks its server directly (unicast) to renew.
  • At 87.5% (T2) it broadcasts to any server.
  • If the lease runs out, the client must stop using the address and start again with DISCOVER.
  • ipconfig /release gives the address back early (a DHCP RELEASE message).

Remember: DORA: Discover and Request are broadcasts from the client; Offer and Ack come from the server. Server port 67, client port 68, UDP.

HOME LABS COMMUNITY DASHBOARD