How to Configure VLANs in Cisco Packet Tracer

Aisyah Aldina

Illustration of separate folders for a guide on configuring VLANs in Cisco Packet Tracer

Hi everyone, this time we are getting into one of the topics that shows up most often in networking exams and hands-on labs: VLANs. With VLANs, one physical switch can be split into several separate networks. PCs in different VLANs cannot talk to each other, even when they are plugged into the same switch and their IP addresses are on the same network.

I do every step directly in Cisco Packet Tracer 8.2.1 with one Cisco 2960 switch and four PCs. I deliberately give all four PCs IP addresses on the same network, so you can see for yourself that what separates them is really the VLAN and not the IP address. If you have never set up a switch before, read my guide on configuring a switch and IP addresses in Cisco Packet Tracer first.

Building the VLAN Topology

Place the switch, PCs, and cables

Cisco Packet Tracer window showing a VLAN topology with one switch and four PCs

The devices are one Cisco 2960-24TT switch and four PCs (PC-PT). Every PC connects to the switch with a Copper Straight-Through cable, because a PC and a switch are different types of devices.

PC0 FastEthernet0  ->  Switch0 FastEthernet0/1  (straight)
PC1 FastEthernet0  ->  Switch0 FastEthernet0/2  (straight)
PC2 FastEthernet0  ->  Switch0 FastEthernet0/3  (straight)
PC3 FastEthernet0  ->  Switch0 FastEthernet0/4  (straight)
Topology with green box for VLAN 10 ADMIN and yellow box for VLAN 20 TAMU

To make the split easy to read, I added colored boxes to the topology. The green box is VLAN 10, named ADMIN, with PC0 and PC1 on ports Fa0/1 and Fa0/2. The yellow box is VLAN 20, named TAMU (Indonesian for guest), with PC2 and PC3 on ports Fa0/3 and Fa0/4. I drew the boxes with the Draw Rectangle icon on the toolbar and picked the fill color in the Palette window, while the labels were made with the Place Note icon.

Set the IP address on every PC

PC0 IP Configuration with the IP address 192.168.1.10 in Cisco Packet Tracer

Click each PC, open Desktop and then IP Configuration, and enter the following IP addresses. The subnet mask fills in automatically as 255.255.255.0 when you click its field.

PC0  192.168.1.10  (VLAN 10)
PC1  192.168.1.11  (VLAN 10)
PC2  192.168.1.12  (VLAN 20)
PC3  192.168.1.13  (VLAN 20)

Test ping before creating the VLANs

Successful ping from PC0 to PC2 before the VLANs are created

Open the Command Prompt on PC0 and ping PC2.

ping 192.168.1.12

Every reply comes back. That is expected, because on a new switch all ports sit in the same VLAN 1, so all four PCs are still on one network.

Configuring VLANs on a Cisco Switch

Create VLAN 10 and VLAN 20

Creating VLAN 10 ADMIN and VLAN 20 TAMU in the Cisco switch CLI

Click the switch, open the CLI tab, then type the following commands.

enable
configure terminal
vlan 10
name ADMIN
exit
vlan 20
name TAMU
exit

The vlan 10 command creates a VLAN with the number 10, and the prompt changes to (config-vlan)#. The name command gives it a name so the VLAN is easy to recognize. For normal use you can pick VLAN numbers from 2 to 1001, because VLAN 1 is the default VLAN.

Assign ports to the VLANs

Assigning ports Fa0/1-2 to VLAN 10 and ports Fa0/3-4 to VLAN 20

Creating the VLANs is not enough on its own. Every port has to be placed in its VLAN. I use interface range so several ports can be configured at once.

interface range fastEthernet0/1-2
switchport mode access
switchport access vlan 10
exit
interface range fastEthernet0/3-4
switchport mode access
switchport access vlan 20
end

switchport mode access turns the port into an access port that carries only one VLAN, which is the right choice for ports connected to PCs. switchport access vlan sets which VLAN the port belongs to. The (config-if-range)# prompt tells you that you are configuring a group of interfaces.

Check the VLAN assignments

Output of show vlan brief with ports assigned to VLAN 10 and VLAN 20
show vlan brief

You can see that VLAN 10 ADMIN holds Fa0/1 and Fa0/2, VLAN 20 TAMU holds Fa0/3 and Fa0/4, and the other ports are still in the default VLAN 1. VLANs 1002 through 1005 are Cisco’s built-in VLANs for older technologies, and you do not need to touch them.

Save the configuration

Saving the VLAN configuration with write memory on a Cisco switch
write memory

Testing Network Separation with VLANs

Ping the same VLAN and a different VLAN

Ping succeeds within the same VLAN but shows Request timed out across VLANs

Go back to the Command Prompt on PC0, then ping PC1 and PC2.

ping 192.168.1.11
ping 192.168.1.12

This screenshot shows three results in a row. The first ping to PC2, before the VLANs were created, succeeds. Once the VLANs are active, the ping to PC1, which is also in VLAN 10, still works, but the ping to PC2 in VLAN 20 now shows Request timed out with Lost = 4 (100% loss).

This is the main job of a VLAN. Even though PC0 and PC2 have IP addresses on the same network and plug into the same switch, the switch does not forward traffic between different VLANs. If PCs in different VLANs need to communicate later on, you need a router or a layer 3 switch to handle inter VLAN routing.

Common Problems and How to Fix Them

PCs in the same VLAN cannot ping each other

Check show vlan brief and make sure both ports are in the same VLAN. A typo in the VLAN number on switchport access vlan is the most common cause.

The message Access VLAN does not exist. Creating vlan appears

This message shows up when you assign a port to a VLAN that has not been created yet. The switch creates that VLAN automatically, without a name. It is not an error, but it is cleaner to give it a name with the vlan command followed by name.

The VLANs disappear after the switch restarts

The configuration was not saved. Run write memory once you finish creating the VLANs.

At this point one switch has been split into two separate networks with VLANs, and you have seen the effect for yourself with ping. In the next article we will connect these VLANs to a second switch using a trunk. If you run into any other error while trying this, just leave a comment below.

Leave a Comment