Typing static IP addresses on every PC does not scale, and in most small and medium networks the router itself hands out addresses with DHCP...
Typing static IP addresses on every PC does not scale, and in most small and medium networks the router itself hands out addresses with DHCP. In this Packet Tracer 8.x lab you will configure a Cisco router as a DHCP server for its own LAN, then use ip helper-address on a second router so PCs on a remote LAN get their addresses from the same server. Along the way I will show you exactly why the relay needs a return route, which is the step most students miss.
Prefer video? Watch more hands-on labs on the Technical Hakim YouTube channel.
How DHCP and DHCP relay work
A DHCP client and server exchange four messages, often remembered as DORA:
- Discover: the client broadcasts to find a server.
- Offer: the server offers an address and options.
- Request: the client asks for the offered address.
- Acknowledge: the server confirms the lease.
The Discover is a broadcast, and routers do not forward broadcasts. So a PC on a LAN without a local DHCP server never reaches the server. A DHCP relay agent fixes this. When the router interface facing the clients has ip helper-address, it catches the broadcast, writes its own interface IP into the "gateway address" (giaddr) field, and forwards the message as a unicast to the server. The server uses giaddr to choose the matching pool and sends its reply back to that address.
Lab topology
Devices: two Cisco 2911 routers, two 2960-24TT switches and four PCs.
- R1 G0/0 connects to SW1 (LAN 10 with PC1 and PC2).
- R1 G0/1 connects to R2 G0/1 (point-to-point link).
- R2 G0/0 connects to SW2 (LAN 20 with PC3 and PC4).
R1 is the DHCP server for both LANs. R2 is the relay agent.
| Device | Interface | IP address | Subnet mask | Notes |
|---|---|---|---|---|
| R1 | G0/0 | 192.168.10.1 | 255.255.255.0 | Gateway for LAN 10, DHCP server |
| R1 | G0/1 | 10.0.0.1 | 255.255.255.252 | Link to R2 |
| R2 | G0/1 | 10.0.0.2 | 255.255.255.252 | Link to R1 |
| R2 | G0/0 | 192.168.20.1 | 255.255.255.0 | Gateway for LAN 20, relay agent |
| PC1, PC2 | Fa0 | DHCP | DHCP | LAN 10 via SW1 |
| PC3, PC4 | Fa0 | DHCP | DHCP | LAN 20 via SW2 |
In each LAN, addresses .1 to .10 are reserved for gateways, servers and printers. Clients get .11 to .254.
Step 1: Interfaces and routing
R1(config)# interface gigabitEthernet 0/0
R1(config-if)# ip address 192.168.10.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# interface gigabitEthernet 0/1
R1(config-if)# ip address 10.0.0.1 255.255.255.252
R1(config-if)# no shutdown
R1(config-if)# exit
R1(config)# ip route 192.168.20.0 255.255.255.0 10.0.0.2
R2(config)# interface gigabitEthernet 0/0
R2(config-if)# ip address 192.168.20.1 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# interface gigabitEthernet 0/1
R2(config-if)# ip address 10.0.0.2 255.255.255.252
R2(config-if)# no shutdown
R2(config-if)# exit
R2(config)# ip route 0.0.0.0 0.0.0.0 10.0.0.1
The static route on R1 to 192.168.20.0/24 is not optional. DHCP replies for LAN 20 are sent to 192.168.20.1 (the giaddr). Without a route to that network, R1 cannot deliver its Offer and the PCs on LAN 20 never get an address. In a bigger network, OSPF would provide this route instead.
Step 2: Configure the DHCP server on R1
R1(config)# ip dhcp excluded-address 192.168.10.1 192.168.10.10
R1(config)# ip dhcp excluded-address 192.168.20.1 192.168.20.10
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
R1(dhcp-config)# exit
R1(config)# ip dhcp pool LAN20
R1(dhcp-config)# network 192.168.20.0 255.255.255.0
R1(dhcp-config)# default-router 192.168.20.1
R1(dhcp-config)# dns-server 8.8.8.8
R1(dhcp-config)# exit
ip dhcp excluded-addresstakes a start and end address that the server will never hand out. Configure exclusions before the pools so the router does not lease a reserved address in the meantime.ip dhcp pool LAN10creates a named pool and enters DHCP configuration mode. The name is only a label.networkdefines the address range of the pool. It takes a dotted-decimal mask (or a prefix length such as/24on real IOS).default-routeris the gateway the client receives. It must be the router interface in that client's subnet, which is why the LAN20 pool points to R2's address, not R1's.dns-serversets the DNS server the client uses. In a lab any address works; on a real network use your actual resolver.
The DHCP service is enabled by default on Cisco IOS. If someone has disabled it, re-enable it with service dhcp.
Step 3: Configure the relay on R2
R2(config)# interface gigabitEthernet 0/0
R2(config-if)# ip helper-address 10.0.0.1
R2(config-if)# end
R2# copy running-config startup-config
The helper address goes on the interface that receives the client broadcasts (G0/0, facing LAN 20), and it points to the DHCP server's IP. A very common mistake is putting it on the WAN interface instead.
Note that on Cisco IOS, ip helper-address forwards a small set of UDP broadcast services by default, not just DHCP (for example TFTP, DNS and NetBIOS name service). That is usually harmless, but it is good to know when you study security.
Step 4: Get addresses on the PCs
On each PC go to Desktop > IP Configuration and select DHCP. Packet Tracer shows "DHCP request successful." when it works. You can also use the command prompt:
C:\>ipconfig /renew
IP Address......................: 192.168.20.11
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.20.1
DNS Server......................: 8.8.8.8
This is PC3 on LAN 20. It received .11 because .1 to .10 are excluded, and the gateway is R2, exactly as configured in the LAN20 pool.
If a PC shows an address starting with 169.254, it did not reach any DHCP server and assigned itself an APIPA (link-local) address. Go to the troubleshooting section below.
Step 5: Verify on the routers
Current leases
R1# show ip dhcp binding
IP address Client-ID/ Lease expiration Type
Hardware address
192.168.10.11 0001.4321.8A01 -- Automatic
192.168.10.12 0060.2F7C.3B12 -- Automatic
192.168.20.11 00D0.BA55.6C21 -- Automatic
192.168.20.12 0030.F219.4A5E -- Automatic
All four PCs have leases from R1, including the two remote PCs on LAN 20. Packet Tracer shows "--" for the expiry time; real IOS shows a date. Your MAC addresses will be different.
Pool usage
R1# show ip dhcp pool LAN20
Pool LAN20 :
Utilization mark (high/low) : 100 / 0
Subnet size (first/next) : 0 / 0
Total addresses : 254
Leased addresses : 2
Excluded addresses : 10
Pending event : none
1 subnet is currently in the pool
Current index IP address range Leased/Excluded/Total
192.168.20.1 192.168.20.1 - 192.168.20.254 2 / 10 / 254
"Leased addresses: 2" confirms PC3 and PC4 were served through the relay.
Relay configuration
R2# show ip interface gigabitEthernet 0/0
GigabitEthernet0/0 is up, line protocol is up (connected)
Internet address is 192.168.20.1/24
Broadcast address is 255.255.255.255
Address determined by setup command
MTU is 1500 bytes
Helper address is 10.0.0.1
...
The "Helper address is 10.0.0.1" line proves the relay is on the right interface. (Output trimmed.)
Address conflicts
Before leasing an address, the IOS DHCP server pings it to check that nobody is using it. If something answers, the address goes into the conflict table instead of being leased. View it with show ip dhcp conflict and clear it with clear ip dhcp conflict *.
Common mistakes
- No return route from the server to the client subnet. LAN 10 works, LAN 20 gets 169.254.x.x. Check
show ip routeon R1 for 192.168.20.0/24. - Helper address on the wrong interface. It must be on the client-facing interface of the relay router (R2 G0/0), not on R2 G0/1.
- Wrong
default-routerin the remote pool. PCs on LAN 20 get an address but cannot leave their subnet because the gateway points to 192.168.10.1. - Exclusions added after clients already leased. A PC may already hold an address you meant to reserve. Run
clear ip dhcp binding *on R1 and renew on the PCs. - Pool network does not match the interface subnet. If the LAN20 pool says 192.168.21.0 by mistake, the server finds no pool matching giaddr 192.168.20.1 and ignores the request.
- Interface still shut down. The relay cannot forward from an interface that is administratively down.
Summary
A Cisco router can be a full DHCP server with just ip dhcp excluded-address and an ip dhcp pool containing network, default-router and dns-server. To serve remote subnets, add ip helper-address on the client-facing interface of the remote router and make sure the server has a route back to that subnet. Verify with ipconfig on the PCs, show ip dhcp binding and show ip dhcp pool on the server, and show ip interface on the relay.
Related tutorials
- Inter-VLAN Routing with Router-on-a-Stick (Packet Tracer Lab)
- OSPF Single-Area Configuration: Full Lab with Verification
- Subnetting Made Simple: /24 to /30 with Worked Examples
- Basic Cisco Router Setup: Hostname, Passwords, Banner and SSH
Sources
- RFC 2131, Dynamic Host Configuration Protocol: https://www.rfc-editor.org/rfc/rfc2131
- RFC 1542, Clarifications and Extensions for the Bootstrap Protocol (relay agent behavior): https://www.rfc-editor.org/rfc/rfc1542
- RFC 3927, Dynamic Configuration of IPv4 Link-Local Addresses: https://www.rfc-editor.org/rfc/rfc3927
- Cisco IP Addressing: DHCP Configuration Guide (Cisco IOS DHCP Server and DHCP Relay Agent)
No comments