4.6 Configure and verify DHCP client and relay
CCNA 200-301 v1.1 · 4.0 IP Services
DHCP gives hosts an address, mask, default gateway and DNS servers automatically, in four messages: Discover, Offer, Request, Acknowledge. The Discover is a broadcast, so it never leaves its VLAN: a DHCP relay (ip helper-address) on the gateway forwards it to a server in another subnet. For the CCNA you configure a router as a DHCP client, as a relay, and read the bindings on the server.
What you must know
- Describe the four DHCP messages (DORA) and their ports.
- Configure a router interface as a DHCP client.
- Configure
ip helper-addresson the gateway of a VLAN and explain what it changes in the packet. - Configure a basic IOS DHCP server to read its bindings.
- Verify leases on the server and on Windows, macOS or Linux hosts.
How a host gets an address
- Discover: the client broadcasts from 0.0.0.0 to 255.255.255.255, UDP 68 to 67.
- Offer: a server proposes an address and options.
- Request: the client asks for the offered address (still a broadcast, so other servers learn their offer was not taken).
- Acknowledge: the server confirms the lease. The client checks the address is free and starts using it.
Leases expire. The client tries to renew at half of the lease time, directly with its server.
DHCP client
A router can take its own address from DHCP, typically on the interface facing an ISP. A default route can come with it.
interface GigabitEthernet0/0
ip address dhcp
no shutdown
!
R1# show dhcp leaseDHCP relay
A broadcast stops at the router. On the gateway interface of the clients' VLAN, ip helper-address catches the Discover and sends it as a unicast to the server (1). The relay writes its own interface address in the giaddr field, and the server uses that address to choose the right pool for the clients' subnet.
interface Vlan10
ip address 10.1.10.1 255.255.255.0
ip helper-address 10.0.50.5A basic IOS DHCP server
ip dhcp excluded-address 10.1.10.1 10.1.10.20
!
ip dhcp pool VLAN10
network 10.1.10.0 255.255.255.0
default-router 10.1.10.1
dns-server 10.0.50.53
lease 7On the hosts, check the result with ipconfig /all (Windows), ipconfig getpacket en0 (macOS) or ip address (Linux). ipconfig /release and /renew force a new exchange.
Commands
show ip dhcp binding | The leases the server has given: address, MAC (client ID) and expiry. |
show ip dhcp pool | Each pool's range, how many addresses are leased and the next one to hand out. |
show ip dhcp conflict | Addresses the server found already in use (by ping or gratuitous ARP). |
show ip interface Vlan10 | Includes the helper address configured on the interface. |
show dhcp lease | On a router that is a DHCP client: its lease. |
Exam traps
ip helper-addressgoes on the interface that receives the clients' broadcasts, not on the server side.- Without
ip dhcp excluded-address, the server may hand out the gateway's own address. - A client with 169.254.x.x (APIPA) heard no answer: check the relay, the pool and DHCP snooping trust.
- DHCP uses UDP 67 on the server and 68 on the client.
- The relay also forwards a few other UDP broadcasts by default (TFTP, DNS, NetBIOS and others).
Check yourself
- Put the four DHCP messages in order.
- Discover, Offer, Request, Acknowledge (DORA).
- Clients in VLAN 20 get no address; the server is in another subnet. What is missing?
ip helper-address <server>on the VLAN 20 gateway interface (the SVI or subinterface).- How does the server know which pool to use for a relayed request?
- From the
giaddrfield, which the relay fills with the address of the interface that received the broadcast. - Which command makes R1 take its outside address from the ISP?
ip address dhcpon that interface.
Labs
Try it live: PAT, DHCP server and NTP
More topics in 4.0 IP Services
- 4.1 Configure and verify NAT for inside hosts using static mappings and address pools
- 4.2 Configure and verify NTP clients and servers
- 4.3 Explain what DHCP and DNS do for hosts
- 4.4 Explain how SNMP is used in network operations
- 4.8 Configure and verify remote device access with SSH
- 4.9 Describe what TFTP and FTP do on a network