This method requires the configuration of two devices: a Layer 2 switch and a router.
On the switch, VLANs are created, physical ports are assigned to the VLANs, and a trunk is configured on the port connected to the router, which we’ll assume is f0/1. On the router side, we’ll assume g0/0/1. In this example, we’ll use only two VLANs (10 and 20) and one PC per VLAN. A native VLAN will also be created.
Switch> enable
Switch# configure terminal
Switch(config)# vlan 10
(config-vlan)#name LAN10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name LAN20
Switch(config-vlan)#exit
Switch(config)#vlan 99
Switch(config-vlan)#name NATIVE
Switch(config-vlan)#exit
Ports are assigned to their respective VLANs, and the trunk is configured.
Switch(config)#interface f0/8
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#interface f0/12
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
S1(config)#interface f0/1
S1(config-if)#switchport mode trunk
S1(config-if)#switchport trunk native vlan 99
S1(config-if)#switchport trunk allowed vlan 10,20,99
Subinterfaces are created, dot1Q encapsulation is enabled, and an IP address is assigned to each subinterface. These subinterfaces will serve as the gateways for their respective VLANs.
R1(config)#interface g0/0/1.10
R1(config-subif)#encapsulation dot1Q 10
R1(config-subif)#ip address 192.168.10.1 255.255.255.0
R1(config-subif)#exit
R1(config)#interface g0/0/1.20
R1(config-subif)#encapsulation dot1Q 20
R1(config-subif)#ip address 192.168.20.1 255.255.255.0
R1(config-subif)#exit
R1(config)#interface g0/0/1.99
R1(config-subif)#encapsulation dot1Q 99 native
R1(config-subif)#exit
R1(config)#interface g0/0/1
R1(config-if)#no shutdown
This method is simpler.
Switch(config)#vlan 10
Switch(config-vlan)#name LAN10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name LAN20
Switch(config-vlan)#exit
Switch(config)#interface vlan 10
Switch(config-if)#ip address 192.168.10.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#interface vlan 20
Switch(config-if)#ip address 192.168.20.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#interface fa0/8
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#interface fa0/12
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
Switch(config)#ip routing
The IP addresses of the VLAN interfaces will be configured on the PCs as their default gateways.
Don’t forget the
ip routing
command to enable packet routing on a Layer 3 switch. By default, it only performs frame switching.