VLAN stands for Virtual Local Area Network and it is used to divide a LAN into multiple segments which also helps to reduce the network traffic. This post is all about how to do basic VLAN configuration and important VLAN command.
We configure VLAN in a networking device switch. By default, all the ports available in a switch are set to VLAN 1. For this reason, all the devices connected to switch in the same network are able to communicate with each other. In this post, we are going to learn how to create multiple VLAN and assign different ports to them.
How to configure VLAN
- Take one switch and 3 PC.
- Connect all the 3 PC to the switch with the help of straight through cable.
- Assign IP Address to all the PC, as 10.0.0.1, 10.0.0.2 and 10.0.0.3.
- Now it’s time to configure the switch. For this, go to CLI Mode (Command Line Interface Mode)
VLAN can be configured in two different modes, database mode and global configuration mode.
How to configure VLAN in database mode:
Note: The below commands I have used for basic VLAN configuration. Kindly follow the instruction so that it will be easy for you to understand the concept.
Instruction:
- Text in bold Green: Indicates the command, I have used to configure VLAN.
- Text in Blue: Indicates the command result.
- Black Text in the bracket (): Indicates the uses of the command and instructions.
Switch>
Switch>en (“en” command is used to enable privilege mode)
Switch# (“#” indicates you have successfully entered the privilege mode)
Switch#vlan database (“vlan database” command is used to enter in database mode)
% Warning: It is recommended to configure VLAN from config mode, as VLAN database mode is being deprecated. Please consult user documentation for configuring VTP/VLAN in config mode.
Switch(vlan)#
Note: It is highly recommended to create a VLAN in global configuration mode. Because database mode is the older version and it may not support on upcoming switches. This is the difference between database and configuration mode in VLAN.
Switch(vlan)#
Switch(vlan)#vlan 2 name production (This is the command to create VLAN, here 2 is the VLAN number and production is VLAN name. Same like this, create all the VLAN)
VLAN 2 added:
Name: production
Switch(vlan)#vlan 3 name sales
VLAN 3 added:
Name: sales
Switch(vlan)#vlan 4 name Production
VLAN 4 added:
Name: Production
Switch(vlan)#
This is how to create VLAN in database mode. Now, let’s see how to create vlan in global configuration mode. before that let’s delete all the VLAN we have created.
How to delete VLAN
Switch(vlan)#
Switch(vlan)#no vlan 2 (“no vlan” is the command used for deleting VLAN. Here 2 is the VLAN number)
Deleting VLAN 2…
Switch(vlan)#no vlan 3
Deleting VLAN 3…
Switch(vlan)#no vlan 4
Deleting VLAN 4…
Switch(vlan)#
Switch(vlan)#
Switch(vlan)#exit (“exit” command is used to exit from the database mode)
APPLY completed.
Exiting….
So, we have successfully deleted all the created VLAN. Now, we are going to create a VLAN in global configuration mode.
How to configure VLAN in global configuration mode
Switch#
Switch#conf t (“conf t” command to enter global configuration mode)
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# (It indicates, we have successfully entered the global configuration mode)
Switch(config)#vlan 2 (“vlan“ is the command used to create a VLAN. Here, 2 is the VLAN number)
Switch(config-vlan)#name production (“name” is the command used to assign a name to the VLAN. Here, production is the vlan name)
Switch(config-vlan)#exit
Switch(config)#vlan 3
Switch(config-vlan)#name sales
Switch(config-vlan)#exit
Switch(config)#vlan 4
Switch(config-vlan)#name marketing
Switch(config-vlan)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#
We have successfully created 3 VLAN (VLAN 2, VLAN 3 and VLAN 4). It is time to assign a port to the VLAN. By default, all the ports are assigned to VLAN1 and for this reason, all the PC connected to the same network are able to communicate with each other.
Switch# show vlan (This command is used to show all the created VLAN and it’s available ports)
VLAN Name Status Ports
—- ——————————– ——— ——————————-
1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
Fa0/5, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, Fa0/11, Fa0/12
Fa0/13, Fa0/14, Fa0/15, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
Gig0/1, Gig0/2
2 production active
3 sales active
4 marketing active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
—- —– ———- —– —— —— ——– —- ——– —— ——
1 enet 100001 1500 – – – – – 0 0
2 enet 100002 1500 – – – – – 0 0
–More–
How to configure ports to the VLAN
Switch#
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#
Switch(config)#int f0/1 (“int” command is used to select the port, “f0/1″ is the port number)
Switch(config-if)#switchport access vlan 2 (“switchport access” command is used to select vlan for the port)
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport access vlan 3
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport access vlan 4
Switch(config-if)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch# show vlan
VLAN Name Status Ports
—- ——————————– ——— ——————————-
1 default active Fa0/4, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig0/1, Gig0/2
2 production active Fa0/1 (Here you can see, Fa0/1, Fa0/2, Fa0/3 are assigned to VLAN 2, 3 and 4)
3 sales active Fa0/2
4 marketing active Fa0/3
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
Now, try to ping from PC 1 to PC 2 or PC 3, it is not going to ping. This is because now all the three PCs belong to the different VLAN.
This is how to configure VLAN in a switch. All the commands I have explained here, are the most commonly used and important VLAN commands.