DHCP per VLAN Configuration in Cisco Packet Tracer

Aisyah Aldina

Illustration of a ticket roll for a guide on DHCP per VLAN in Cisco Packet Tracer

Hi everyone, in the inter VLAN routing article we still typed the IP address on every PC by hand. Once each VLAN has dozens of PCs, that quickly becomes a chore. In this article I turn the same router into a DHCP server for each VLAN, so PCs in VLAN 10 automatically get a 192.168.10.x address and PCs in VLAN 20 automatically get a 192.168.20.x address.

I did everything directly in Cisco Packet Tracer 8.2.1, continuing the router on a stick topology from my guide on inter VLAN routing configuration in Cisco Packet Tracer. If you have never set up DHCP on a Cisco router before, the basics are covered in how to configure a DHCP server on a Cisco router in Packet Tracer.

The Topology Used

Check the topology and cables

Cisco Packet Tracer window showing a DHCP per VLAN topology with router on a stick

The topology has 1 Cisco 1941 router, 1 Cisco 2960-24TT switch, and 4 PCs. The router and the switch are linked by a single cable that works as the trunk.

Topology with a 1941 router, 2960 switch, and four PCs in VLAN 10 and VLAN 20

The green box is VLAN 10 and the yellow box is VLAN 20. Every cable is Copper Straight-Through.

PC0 FastEthernet0      ->  Switch0 FastEthernet0/1     (straight, VLAN 10)
PC1 FastEthernet0      ->  Switch0 FastEthernet0/2     (straight, VLAN 10)
PC2 FastEthernet0      ->  Switch0 FastEthernet0/3     (straight, VLAN 20)
PC3 FastEthernet0      ->  Switch0 FastEthernet0/4     (straight, VLAN 20)
Router0 Gig0/0         ->  Switch0 GigabitEthernet0/1  (straight, trunk)

The router already has subinterface Gig0/0.10 with IP 192.168.10.1 and Gig0/0.20 with IP 192.168.20.1. DHCP will hand out these two addresses as the gateways.

Configuring DHCP for Each VLAN

Create the excluded addresses and a pool per VLAN

Excluded addresses and DHCP pools VLAN10 and VLAN20 configured on a Cisco router

Open the router CLI and type the following commands.

configure terminal
ip dhcp excluded-address 192.168.10.1 192.168.10.9
ip dhcp excluded-address 192.168.20.1 192.168.20.9
ip dhcp pool VLAN10
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 VLAN20
network 192.168.20.0 255.255.255.0
default-router 192.168.20.1
dns-server 8.8.8.8
end
write memory

I reserve .1 through .9 in each VLAN for the router, the switch, and any other device that needs a fixed IP. Each VLAN gets its own pool with a matching network and default-router.

So how does the router know which pool belongs to which PC? A DHCP request from a PC in VLAN 10 reaches the router through subinterface Gig0/0.10, which has the IP 192.168.10.1. The router then picks the pool whose network matches that subinterface IP, which is pool VLAN10. The same thing happens for VLAN 20.

Switching the PCs to DHCP Mode

The PC in VLAN 10 gets an IP automatically

PC0 in VLAN 10 receiving IP 192.168.10.10 from DHCP

Click PC0, open Desktop and then IP Configuration, and select DHCP. Once DHCP request successful appears, PC0 has IP 192.168.10.10, subnet mask 255.255.255.0, gateway 192.168.10.1, and DNS 8.8.8.8. The .10 address is the first one right after the excluded range.

The PC in VLAN 20 gets an IP from a different pool

PC2 in VLAN 20 receiving IP 192.168.20.10 from DHCP

Do the same on PC2. Because PC2 sits in VLAN 20, it receives 192.168.20.10 with gateway 192.168.20.1. On my machine, PC1 got 192.168.10.11 and PC3 got 192.168.20.11.

Testing the Connection and Checking the Router

Check the IP and ping the other VLAN

ipconfig and ping output from PC1 in VLAN 10 to PC3 in VLAN 20

Open the Command Prompt on PC1 and run the following commands.

ipconfig
ping 192.168.20.11

ipconfig shows IP 192.168.10.11 and gateway 192.168.10.1 from DHCP. The ping to PC3 in VLAN 20 succeeds, which means the gateway handed out by DHCP is correct and inter VLAN routing still works.

See the list of leased IP addresses

Output of show ip dhcp binding listing IP addresses from two VLANs

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

show ip dhcp binding

All four PCs show up with IP addresses that match their VLANs, two from the 192.168.10.0 network and two from 192.168.20.0, along with their MAC addresses.

Common Problems and How to Fix Them

A PC in one of the VLANs gets a 169.254.x.x address

DHCP failed for that VLAN. Check that the router subinterface for that VLAN is up and that the pool network matches the subinterface network.

A PC gets an IP from the wrong VLAN

This usually means the switch port is in the wrong VLAN. Run show vlan brief on the switch and make sure the PC port belongs to the correct VLAN.

DHCP works in VLAN 10 but not in VLAN 20

Make sure the trunk between the switch and the router carries VLAN 20 by running show interfaces trunk on the switch, and confirm that encapsulation dot1Q 20 is set on the router subinterface.

At this point every VLAN gets its IP addresses automatically from the router, and PCs in different VLANs can still talk to each other. In the next article we will move on to static routing to connect several routers. If you run into any other error while trying this, just leave a comment below.

Leave a Comment