VLAN configuration is a crucial aspect of network segmentation and management. In Global Configuration mode, you can use the following commands:
| Command | Description |
|---|---|
vlan <vlan-id> |
Creates a VLAN |
name <vlan-name> |
Assigns a name to the VLAN |
switchport access vlan <vlan-id> |
Sets the VLAN that the interface belongs to |
no vlan <vlan-id> |
Deletes a VLAN |
show vlan |
Display the VLAN configuration |
The example below shows the commands for basic port configuration:
Switch(config)#vlan 10
Switch(config-vlan)#name wireless
Switch(config-vlan)#exit
Switch (config)#interface FastEthernet 0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config-if)#
Spanning Tree Protocol (STP) Commands
Spanning Tree Protocol is a feature of Cisco switches that can help prevent network loops. STP is enabled by default on Cisco switches for all VLANs. You can modify STP settings globally for the entire switch, or apply specific configurations to individual interfaces or VLANs for fine-tuned control over the STP behavior across different parts of your network. The command is as follows:
spanning-tree mode rapid-pvst
Configuring Trunk Ports
Ports that need to carry multiple VLAN traffic need to be trunked. You first need to trunk the port and then assign the VLANs. Configuring trunk ports on Cisco switches involves using the following commands:
| Command | Description |
|---|---|
switchport trunk native vlan <vlan-id> |
Enables trunk mode for the port and sets the native VLAN for untagged traffic on the trunk |
switchport trunk allowed vlan <vlan-id> |
Adds the specified VLANs to the current list |
switchport trunk allowed vlan remove <vlan-id> |
Removes the specified VLANs from the allowed list |
The example below shows these VLAN commands in action:
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config) #interface GigabitEthernet0/1
Switch(config-if)# switchport trunk native vlan 40
Switch(config-if)# switchport trunk allowed vlan 10
Switch(config-if)# switchport trunk allowed vlan 20,30
Switch(config-if)# switchport trunk allowed vlan remove 10
Switch(config-if)#