Lab Objective
Configure a router with two subinterfaces on a single physical interface, connect it to a switch trunk carrying two VLANs, and verify hosts in each VLAN can reach each other through the router.
Lab Purpose
Before a Layer 3 switch with SVIs is available or justified, router-on-a-stick remains a common, simple way to enable inter-VLAN routing using a single router interface and a trunk link, especially in smaller networks or lab environments.
Lab Topology
R1 ---- Gi0/0 (trunk) ---- Switch1
Switch1:
Gi1/0/1 ---- PC-A (VLAN 10): 192.168.10.10/24
Gi1/0/2 ---- PC-B (VLAN 20): 192.168.20.10/24
Gi1/0/24 ---- trunk to R1
R1 subinterfaces:
Gi0/0.10: 192.168.10.1/24 (VLAN 10)
Gi0/0.20: 192.168.20.1/24 (VLAN 20)Task 1: Configure the Switch Trunk and VLANs
Create VLANs 10 and 20 on Switch1, assign Gi1/0/1 to VLAN 10 and Gi1/0/2 to VLAN 20, and configure Gi1/0/24 as a trunk allowing both VLANs.
Task 2: Configure the Router's Physical Interface
Bring up Gi0/0 on R1 without assigning it an IP address directly.
Task 3: Configure the Subinterfaces
Create subinterfaces Gi0/0.10 and Gi0/0.20 with appropriate 802.1Q encapsulation and IP addresses.
Task 4: Configure PC Default Gateways
Set PC-A's default gateway to R1's Gi0/0.10 address, and PC-B's to Gi0/0.20's address.
Task 5: Verify Inter-VLAN Connectivity
Confirm PC-A can ping PC-B across the two VLANs.
Solution and Verification
Switch1(config)# vlan 10
Switch1(config-vlan)# exit
Switch1(config)# vlan 20
Switch1(config-vlan)# exit
Switch1(config)# interface gigabitethernet1/0/1
Switch1(config-if)# switchport mode access
Switch1(config-if)# switchport access vlan 10
Switch1(config-if)# exit
Switch1(config)# interface gigabitethernet1/0/2
Switch1(config-if)# switchport mode access
Switch1(config-if)# switchport access vlan 20
Switch1(config-if)# exit
Switch1(config)# interface gigabitethernet1/0/24
Switch1(config-if)# switchport mode trunkR1(config)# interface gigabitethernet0/0
R1(config-if)# no shutdown
R1(config-if)# exitR1(config)# interface gigabitethernet0/0.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 gigabitethernet0/0.20
R1(config-subif)# encapsulation dot1Q 20
R1(config-subif)# ip address 192.168.20.1 255.255.255.0PC-A: default gateway 192.168.10.1
PC-B: default gateway 192.168.20.1PC-A> ping 192.168.20.10
Reply from 192.168.20.10: bytes=32 time=2ms
R1# show ip route
C 192.168.10.0/24 is directly connected, GigabitEthernet0/0.10
C 192.168.20.0/24 is directly connected, GigabitEthernet0/0.20Key Takeaway
Each subinterface's encapsulation dot1Q command must exactly match the VLAN number carried on the corresponding trunk tag — forgetting this command, or specifying the wrong VLAN number, is the most common cause of a router-on-a-stick configuration that appears correct but fails to route traffic for that specific VLAN.