Configuring DHCP on Routers and Switches: A Complete Guide
DHCP (Dynamic Host Configuration Protocol) can be configured on routers and switches to automatically assign IP addresses to devices in a network. This eliminates manual IP configuration and simplifies network management.
1. Why Configure DHCP on Routers/Switches?
Key Benefits:
- ✅ Automates IP assignment – No need to manually set IPs for each device.
- ✅ Centralized control – Manage IP ranges, DNS, and gateways from one place.
- ✅ Prevents IP conflicts – The DHCP server ensures no two devices get the same IP.
-
✅ Supports multiple subnets – DHCP Relay (
ip helper-address) allows serving multiple VLANs.
When to Use DHCP:
- Small networks – Router acts as DHCP server.
- Enterprise networks – Core router or dedicated server handles DHCP.
-
Multi-VLAN environments – Switches forward DHCP
requests via
ip helper-address.
2. How DHCP Works on Routers & Switches
Two Main Roles:
- DHCP Server – Assigns IPs to clients (router/switch/server).
- DHCP Relay Agent – Forwards requests to remote DHCP servers (router/switch).
3. DHCP Configuration on a Router (as a Server)
Network Setup:
- Subnet:
192.168.1.0/24 - DHCP Pool:
192.168.1.10 - 192.168.1.100 - Default Gateway:
192.168.1.1 - DNS:
8.8.8.8
Step-by-Step Configuration
Router> enable
Router# configure terminal
! Define DHCP pool
Router(config)# ip dhcp pool LAN_POOL
Router(dhcp-config)# network 192.168.1.0 255.255.255.0
Router(dhcp-config)# default-router 192.168.1.1
Router(dhcp-config)# dns-server 8.8.8.8
Router(dhcp-config)# lease 7
! Exclude static IPs
Router(config)# ip dhcp excluded-address 192.168.1.1 192.168.1.9
! Enable DHCP service (if disabled)
Router(config)# service dhcp
Router(config)# end
Router# write memory
Verification Commands
Router# show ip dhcp binding
Router# show ip dhcp pool
Router# debug ip dhcp server events
4. DHCP Relay (ip helper-address) on a Switch/Router
When to Use: When the DHCP server is in a different subnet or VLAN.
Example Setup:
- VLAN 10:
192.168.10.0/24 - DHCP Server:
10.0.0.5
Switch> enable
Switch# configure terminal
! Enable IP routing
Switch(config)# ip routing
! VLAN interface
Switch(config)# interface vlan 10
Switch(config-if)# ip address 192.168.10.1 255.255.255.0
Switch(config-if)# ip helper-address 10.0.0.5
Switch(config-if)# no shutdown
Switch(config-if)# end
Switch# write memory
Verification
Switch# show ip interface vlan 10
Switch# debug ip dhcp relay
5. DHCP on a Switch (Layer 2 vs. Layer 3)
-
Layer 2 Switch: Cannot assign IPs; may forward
requests with
ip helper-address. - Layer 3 Switch: Can act as a DHCP server.
Switch(config)# ip dhcp pool OFFICE_POOL
Switch(dhcp-config)# network 192.168.20.0 255.255.255.0
Switch(dhcp-config)# default-router 192.168.20.1
Switch(dhcp-config)# dns-server 8.8.8.8
6. Real-World Example: Office Network
Scenario:
-
Main Router provides DHCP for
192.168.1.0/24. - Switch connects VLANs (HR, IT, Guest).
- DHCP Server at
10.0.0.5.
! Router DHCP config
ip dhcp pool MAIN_LAN
network 192.168.1.0 255.255.255.0
default-router 192.168.1.1
! Switch as relay
interface vlan 20
ip helper-address 10.0.0.5
7. Troubleshooting DHCP Issues
| Problem | Solution |
|---|---|
| Clients not getting IP | Check ip helper-address, DHCP pool, lease availability |
| IP conflicts | Use ip dhcp excluded-address for reserved/static IPs |
| DHCP server unreachable | Verify routing and firewall rules |
show ip dhcp conflict
clear ip dhcp binding *
8. Summary
- Router as DHCP Server: Best for small networks
- Switch as DHCP Relay: For VLAN/multi-subnet environments
- Enterprise: Use central DHCP server + relay agents
By configuring DHCP correctly, you ensure automatic, conflict-free IP assignment across your network.