How to Configure DHCP Server For Multiple VLANS in Packet Tracer

The dynamic host configuration protocol is a protocol that automatically assigns an IP address to any host devices connected to a network. Once any host device that has DHCP enabled is connected to a network that has a DHCP server, it will automatically obtain an IP address from the DHCP server. This is normally used in a large network, where configuring a static IP address for each of the host devices is difficult.

DHCP employs client-server communication. The client, which is normally a host device like a PC, laptop, or server, sends a DHCP request message, and the server, which can be a dedicated server, a router, a layer 3 switch, or even a layer 2 switch, leases an IP address to the client, which it can use during its period of connection to the network.

A DHCP request and reply is normally a broadcast message, and this broadcast message does not transverse from one VLAN to another. Each VLAN is a broadcast domain; hence, when we have multiple VLANs in a network, we need to configure a separate DHCP pool for each of the VLANs.

In this post, I will show you how to Configure DHCP Server For Multiple VLANS in the packet tracer.

Network Topology

The network topology we will be making use of in this post is shown below. As you can see, it consists of a layer 3 switch, a layer 2 switch, and then four PCs. The four PCs are attached to the layer 2 switch, and they are divided into two VLANs: VLAN 10 and VLAN 20. In this demonstration, we will create the VLANs, assign the PCs appropriately to the respective VLAN, and then configure DHCP for the multiple VLANs.

network topology comprising of layer 3 switch, layer 2 switch and pcs

 

How to Configure DHCP Server For Multiple VLANS in Packet Tracer

Here are steps to configure DHCP server for multiple VLANs;

Step 1: Create the VLANs

As shown the network topology, we will be needing two VLANs in this demonstration. Enter the following commands to created the VLANs on the layer 2 switch.

Switch0

Switch>enable
Switch#configure terminal
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#vlan 10

 Step 2: Configure Access port

By default, all the PCS on the layer 2 switch are on VLAN 1. We need to change their access from VLAN 1 to their appropriate VLANs.

Switch0

Switch(config)#int range fa0/2-3
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 20
Switch(config-if-range)#exit
Switch(config)#interface range fa0/4-5
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 10
Switch(config-if-range)#exit
Switch(config)#interface fa0/1
Switch(config-if)#switchport mode trunk

Note: The last two commands configured the fa0/1 interface of the switch as a trunk port. This is because it carries traffic from all vlans.

Step 3: Configure DHCP server

In this demonstration, we will configure the layer 2 switch as a DHCP server. Because there is two VLANs existing on the network, we will configure two DHCP pool for the two VLANs. This is because, DHCP request and reply does not transverse from one VLAN to another.

Switch0

Switch(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.5
Switch(config)#ip dhcp excluded-address 192.168.2.1 192.168.2.5
Switch(config)#ip dhcp pool Firstpool
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0
Switch(dhcp-config)#default-router 192.168.1.1
Switch(dhcp-config)#dns-server 192.168.1.2
Switch(dhcp-config)#exit
Switch(config)#ip dhcp pool secondpool
Switch(dhcp-config)#network 192.168.2.0 255.255.255.0
Switch(dhcp-config)#default-router 192.168.2.1
Switch(dhcp-config)#dns-server 192.168.2.2

In the above command, we created two DHCP pools: Firstpool and Secondpool. Firstpool will be used for VLAN1, and Secondpool will be used for VLAN2. We have a separate post on how to configure a DHCP server where we explain what each of the above commands does.

To enable the layer 2 switch to be able to receive DHCP request appropriately from the host devices and leased them an IP address, we need to assign IP address to its vlan interfaces. VLAN 10 will receive an IP address in the 192.168.1.0 network and VLAN 20 will receive an IP address in 192.168.2.0 network.

Switch0

Switch(config)#interface vlan 10
Switch(config-if)#ip address 192.168.1.3 255.255.255.0
Switch(config-if)#exit
Switch(config)#interface vlan 20
Switch(config-if)#ip address 192.168.2.3 255.255.255.0

 Step 4: Enable DHCP on the DHCP Clients

On each of the PCs, go to Desktop>IP Configuration and enable DHCP. Once you enable DHCP, the PC will send a DHCP request to the server (layer 2 switch), and it will be provided with IP in the PC’s appropriate VLAN.

PC in VLAN 10;

enable DHCP on DHCP client

As show in the image above, PC0 received an IP address from the network 192.168.1.0 which is the network address for VLAN 10.

PC in VLAN 20;

enable dhcp on dhcp client2

Step 5: Enable Inter-VLAN routing

For PCs on VLAN 10 to be able to communicate with PCs on VLAN 20, we need to enable inter-VLAN routing on the layer 3 switch.

Multilayer Switch0

Switch>enable
Switch#configure terminal
Switch(config)#interface fa0/1
Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk
Switch(config-if)#exit
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#interface vlan 10
Switch(config-if)#ip address 192.168.1.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#interface vlan 20
Switch(config-if)#ip address 192.168.2.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#ip routing

The command above configures the port the layer 3 switch is using to connect to layer 2 switch as a trunkport and then creates an SVI with IP address 192.168.1.1 for VLAN 10 and 192.168.2.1 for VLAN 20.

Note: The IP address of the SVI must correspond to the default-router IP address that we configured on the DHCP pool for each of the VLANs. For instance, the default-router IP address for Firstpool, which is the pool for VLAN 10, is 192.168.1.1, and the SVI IP address for VLAN 10 is also 192.168.1.1.

Step 6: Test connectivity

Ping from PCs on VLAN 10 to PCs on VLAN 20 to test inter-vlan  Connectivity.

Testing inter-vlan connectivity

Here is a video on how to configure DHCP server for multiple VLANS;

Related content;

How to Configure DHCP Snooping In Cisco Packet Tracer

DHCPv4 Server & DHCPv4 Client Configuration on Cisco Router

How to Configure DHCP on Layer 2 Switch in Packet Tracer

How to Configure DHCP Relay Agent on Layer 3 Switch

How to Configure DHCP on Layer 3 Switch In Packet Tracer

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top