Set Up a DHCP Server on a Cisco Router in Packet Tracer

Aisyah Aldina

Illustration of an address tag for a guide on configuring a DHCP server on a Cisco router

Hi everyone, in the previous article we typed the IP address on every PC by hand. That is still fine for four PCs, but imagine doing it for fifty PCs in one office. Here I turn a Cisco router into a DHCP server, so every PC gets its IP address, subnet mask, gateway, and DNS automatically as soon as it joins the network.

I do every step directly in Cisco Packet Tracer 8.2.1 with the same topology as my guide on how to set up a router and switch in Cisco Packet Tracer: one 1941 router, two 2960 switches, and four PCs on two different networks. A single router serves DHCP for both networks at once.

The Topology Used

Check the topology and cables

Topology of a 1941 router, two switches, and four PCs for DHCP in Packet Tracer

Every link uses the Copper Straight-Through cable, because a router and a switch, like a PC and a switch, are different types of devices.

Router0 GigabitEthernet0/0  ->  Switch0 GigabitEthernet0/1  (straight)
Router0 GigabitEthernet0/1  ->  Switch1 GigabitEthernet0/1  (straight)
PC0 FastEthernet0           ->  Switch0 FastEthernet0/1     (straight)
PC1 FastEthernet0           ->  Switch0 FastEthernet0/2     (straight)
PC2 FastEthernet0           ->  Switch1 FastEthernet0/1     (straight)
PC3 FastEthernet0           ->  Switch1 FastEthernet0/2     (straight)

The router interfaces already have the IP 192.168.10.1 on Gig0/0 and 192.168.20.1 on Gig0/1. These two addresses will be the gateways that DHCP hands out to the PCs.

Configuring the DHCP Server on a Cisco Router

Create the excluded addresses and DHCP pools

Configuring excluded addresses and the LAN10 and LAN20 DHCP pools on a Cisco router

Open the router CLI, enter enable mode, then type the following commands.

configure terminal
ip dhcp excluded-address 192.168.10.1 192.168.10.10
ip dhcp excluded-address 192.168.20.1 192.168.20.10
ip dhcp pool LAN10
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
dns-server 8.8.8.8
exit
ip dhcp pool LAN20
network 192.168.20.0 255.255.255.0
default-router 192.168.20.1
dns-server 8.8.8.8
end

Here is what each command does:

ip dhcp excluded-address sets a range of IP addresses that DHCP must never hand out. I reserve .1 through .10 for devices that need a fixed IP, such as routers, switches, servers, and printers.

ip dhcp pool LAN10 creates a group of DHCP settings named LAN10, and the prompt changes to (dhcp-config)#. You can name the pool anything you like. I simply named it after its network.

network sets the network this pool serves. The router automatically answers PCs that arrive through the interface on the matching network, so the PCs on Switch0 get an IP from LAN10 and the PCs on Switch1 get one from LAN20.

default-router is the gateway sent to the PCs, and it must match the router interface IP on that network.

dns-server is the DNS address sent to the PCs.

Note: The excluded-address command is typed in global configuration mode, not inside the pool. If you type it inside the pool by mistake, you will get an Invalid input message.

Switching the PCs to DHCP Mode

Select DHCP in IP Configuration

PC0 receives IP 192.168.10.11 from DHCP with the DHCP request successful message

Click PC0, open Desktop and then IP Configuration, and select DHCP. Within a few seconds the message DHCP request successful appears. The IPv4 Address, Subnet Mask, Default Gateway, and DNS Server fields fill in automatically with 192.168.10.11, 255.255.255.0, 192.168.10.1, and 8.8.8.8.

PC0 gets .11 because .1 through .10 are excluded, so DHCP hands out the first free address. Do the same on PC1, PC2, and PC3. On my machine PC1 got 192.168.10.12, PC2 got 192.168.20.11, and PC3 got 192.168.20.12.

Check the IP details with ipconfig

Output of ipconfig /all on PC0 showing DHCP Servers 192.168.10.1 and DNS 8.8.8.8

Open the Command Prompt on PC0 and run the following command.

ipconfig /all

Besides the IP and gateway, you can also see DHCP Servers 192.168.10.1, which is the router that assigned the IP, and DNS Servers 8.8.8.8, just as set in the pool.

Testing Connectivity and Checking the Router

Ping another network

Successful ping from PC0 to PC3 on the 192.168.20.0 network
ping 192.168.20.12

The ping from PC0 to PC3 on the 192.168.20.0 network succeeds. This means the gateway handed out by DHCP is correct, because without a gateway a PC cannot reach other networks.

View the list of assigned IP addresses

Output of show ip dhcp binding listing the IP and MAC address of four PCs

Go back to the router CLI and run the following command.

show ip dhcp binding

This table lists the IP addresses that have been leased along with the MAC address of each PC that received one. All four PCs show up here with the type Automatic.

View the pool statistics

Output of show ip dhcp pool LAN10 showing 2 leased addresses out of 254
show ip dhcp pool LAN10

The Leased addresses line shows that 2 addresses have been leased from the LAN10 pool, for PC0 and PC1, out of a total of 254 addresses in the range 192.168.10.1 to 192.168.10.254.

Save the configuration

Saving the Cisco router DHCP configuration with the write memory command
write memory

Common Problems and How to Fix Them

The PC gets a 169.254.x.x address

This means the DHCP request failed and the PC assigned itself an address. Check that the router interface has no shutdown applied, that every cable is green, and that the pool has a network command matching the router interface network.

The PC gets an IP but cannot ping another network

Check the default-router command in the pool. The gateway it hands out must exactly match the router interface IP on that network, for example 192.168.20.1 for the LAN20 pool.

The message DHCP request failed appears

Click Static and then DHCP again to send a fresh request. If it still fails, make sure there is no other pool with the same network and that the pool has not run out of addresses.

At this point the Cisco router is acting as a DHCP server for two networks, and every PC gets its IP address automatically. In the next article we will access the router and switch remotely using Telnet and SSH. If you run into any other error while trying this, just leave a comment below.

Leave a Comment