Cisco routers and switches can be configured to act s a DHCP server with just a few commands—a feature useful in the lab and in some limited cases. More commonly, the enterprise uses a centralized DHCP server (that does not run on a router) but with the router DHCP relay feature on most every router interface.
Finally, Cisco routers and switches can also act as DHCP clients, learning their IP addresses from a DHCP server.
Configuring DHCP Server
- Rt1(config)#ip dhcp excluded-address 192.168.2.1 192.168.2.10
- Rt1(config)#ip dhcp pool NEXTGENCCNAS-DHCPSVR
- Rt1(dhcp-config)#network 192.168.2.0 255.255.255.0
- Rt1(dhcp-config)#default-router 192.168.2.1
- Rt1(dhcp-config)#dns-server 192.168.2.1
- Rt1(dhcp-config)#exit
Configuring DHCP Client
For Switch, the IP address is for management purposes
- Sw1(config)#interface vlan 1
- Sw1(config-if)#ip address dhcp
- Sw1(config-if)#no shut
For other client
- Router(config)#interface f0/0
- Router(config-if)#ip address dhcp
- Router(config-if)#no shut
Configuring DHCP for Relay Agent
There are three (3) subnets in the diagram, the dhcp server controls the ip addressing to the first subnet which is 192.162.2.0/24. Other routers are the relay agents and as such, the following commands will have to be put on the outgoing interface for each of the routers and as many other routers that will act as a relay agents. The following step will help setup the ip helper-address on the DHCP relay agents;
- Setup the DHCP pool for the relay agent subnets on the main DHCP server
- setup a routing protocol that will route between the subnets
- setup the ip helper-address on the outgoing interfaces concerned of the relay agents
Step 1
DHCP Pool for Relay Agent-1 for the subnet 192.168.3.0/24 on DHCP Server
- Rt2(config)#ip dhcp excluded-address 192.168.3.1 192.168.3.10
- Rt2(config)#ip dhcp pool nextgenccna-dhcp-pool2
- Rt2(dhcp-config)#network 192.168.3.0 255.255.255.0
- Rt2(dhcp-config)#default-router 192.168.3.1
- Rt2(dhcp-config)#exit
DHCP Pool for Relay Agent-2 for the subnet 192.168.4.0/24 on DHCP Server
- Rt1(config)#ip dhcp excluded-address 192.168.4.1 192.168.4.10
- Rt1(config)#ip dhcp pool nextgenccna-dhcp-pool3
- Rt1(dhcp-config)#network 192.168.4.0 255.255.255.0
- Rt1(dhcp-config)#default-router 192.168.4.1
- Rt1(dhcp-config)#exit
Step 2
Routing for Rt1, Rt2 & Rt3
- Rt1(config)#router ospf 1
- Rt1(config-router) # network 192.168.1.0 o.o.0.255 area 0
- Rt1(config-router) # network 192.168.2.0 o.o.0.255 area 0
- Rt2(config)#router ospf 1
- Rt2(config-router) # network 192.168.1.0 o.o.0.255 area 0
- Rt2(config-router) # network 192.168.3.0 o.o.0.255 area 0
- Rt2(config-router) # network 10.10.10.0 o.o.0.255 area 0
- Rt3(config)#router ospf 1
- Rt3(config-router) # network 192.168.4.0 o.o.0.255 area 0
- Rt3(config-router) # network 10.10.10.0 o.o.0.255 area 0
Step 3
Configure IP helper-address on Rt2 & Rt3
- Rt2(config)#interface f1/0
- Rt2(config-if)#ip helper-address 192.168.1.1
- Rt3(config)#interface f1/0
- Rt3(config-if)#ip helper-address 192.168.1.1
Verify
To view information about the currently leased addresses,
- Rt1(config-if)#do show ip dhcp binding
- IP address Client-ID/ Lease expiration Type
- Hardware address
- 192.168.1.11 0060.4785.0E2D — Automatic
- 192.168.1.12 00D0.5868.1C83 — Automatic
- Rt1(config-if)#
To display information about the configured DHCP pools,
- Rt1(config-if)#do show ip dhcp pool
- Pool nextgenccna-dhcp-lab :
- Utilization mark (high/low) : 100 / 0
- Subnet size (first/next) : 0 / 0
- Total addresses : 254
- Leased addresses : 2
- Excluded addresses : 1
- Pending event : none
- 1 subnet is currently in the pool
- Current index IP address range Leased/Excluded/Total
- 192.168.1.1 192.168.1.1 – 192.168.1.254 2 / 1 / 254
- Rt1(config-if)#
To modify the default DHCP lease time for a pool of IP addresses, use the lease configuration command:
- Router1(config)#
ip dhcp pool
172.25.2.0/24
- Router1(dhcp-config)#
lease 2 12 30
- Router1(dhcp-config)#
exit
- Router1(config)#
end
- Router1#