Inter-VLAN Routing — Router-on-a-Stick
VLANs are separate broadcast domains — a device in VLAN 10 cannot communicate with a device in VLAN 20 without passing through a Layer 3 device. Router-on-a-Stick is the classic solution: a single physical cable connects a router to a switch as a trunk link, and the router uses subinterfaces — one per VLAN — to route traffic between them. All inter-VLAN routing flows over that single trunk link, which is why it is called "router-on-a-stick."
Before starting, complete VLAN Creation and Management, Assigning VLANs to Switch Ports, and Trunk Port Configuration. This lab builds directly on all three.
1. How Router-on-a-Stick Works
A standard router interface can only be in one subnet. To route between multiple VLANs over a single physical link, IOS supports subinterfaces — logical subdivisions of a physical interface, each configured with its own IP address and 802.1Q VLAN encapsulation.
| Component | Role |
|---|---|
Physical interface (e.g., Gi0/0) |
Must be enabled (no shutdown) but has no IP address itself |
Subinterface (e.g., Gi0/0.10) |
One per VLAN — has an IP address and 802.1Q encapsulation set to that VLAN's ID |
| Trunk link (switch side) | Switch port facing the router must be configured as a trunk port |
| Default gateway (PC side) | Each PC's default gateway is set to the IP address of its VLAN's subinterface |
Traffic Flow — VLAN 10 to VLAN 20
When PC1 (VLAN 10) sends a packet to PC2 (VLAN 20), here is what happens step by step:
| Step | What Happens |
|---|---|
| 1 | PC1 sends the packet to its default gateway: 192.168.10.1 (the router's Gi0/0.10 subinterface) |
| 2 | The switch receives the frame on PC1's access port (VLAN 10), tags it with VLAN 10, and forwards it up the trunk to the router |
| 3 | The router receives the tagged frame on Gi0/0, reads the VLAN 10 tag, and processes it on subinterface Gi0/0.10 |
| 4 | The router makes a routing decision — the destination (192.168.20.x) is reachable via Gi0/0.20 |
| 5 | The router forwards the packet out Gi0/0.20, tagging it with VLAN 20 |
| 6 | The switch receives the VLAN 20 tagged frame, strips the tag, and delivers it to PC2's access port |
Router-on-a-Stick vs Layer 3 Switch
| Feature | Router-on-a-Stick | Layer 3 Switch (SVI) |
|---|---|---|
| Hardware needed | Router + switch (two devices) | One multilayer switch |
| Bottleneck | All inter-VLAN traffic flows through one physical link | Routing done internally at wire speed |
| Cost | Lower — reuses existing router | Higher — multilayer switch required |
| Best for | Small networks, labs, CCNA exam scenarios | Enterprise networks with high inter-VLAN traffic |
| CCNA exam coverage | ✅ Core topic | ✅ Core topic — see Layer 3 Switch Lab |
2. Lab Topology & IP Addressing
┌─────────────────┐
│ NetsTuts_R1 │
│ │
│ Gi0/0.10 ──── 192.168.10.1/24 (VLAN 10 gateway)
│ Gi0/0.20 ──── 192.168.20.1/24 (VLAN 20 gateway)
│ Gi0/0.30 ──── 192.168.30.1/24 (VLAN 30 gateway)
│ Gi0/0 (trunk) │
└────────┬────────┘
│ 802.1Q Trunk
│ (Gi0/0 ←→ Gi0/1)
┌────────┴────────┐
│ NetsTuts_SW1 │
├─────────────────┤
│ Fa0/1 → VLAN 10 │──── PC1 (192.168.10.10/24 GW: 192.168.10.1)
│ Fa0/2 → VLAN 20 │──── PC2 (192.168.20.10/24 GW: 192.168.20.1)
│ Fa0/3 → VLAN 30 │──── PC3 (192.168.30.10/24 GW: 192.168.30.1)
└─────────────────┘
| Device | Interface | IP Address | VLAN | Role |
|---|---|---|---|---|
| NetsTuts_R1 | Gi0/0.10 | 192.168.10.1 /24 | 10 | Default gateway for VLAN 10 |
| NetsTuts_R1 | Gi0/0.20 | 192.168.20.1 /24 | 20 | Default gateway for VLAN 20 |
| NetsTuts_R1 | Gi0/0.30 | 192.168.30.1 /24 | 30 | Default gateway for VLAN 30 |
| NetsTuts_SW1 | Gi0/1 | N/A (trunk) | All | Trunk link to router |
| PC1 | NIC | 192.168.10.10 /24 | 10 | End device — VLAN 10 |
| PC2 | NIC | 192.168.20.10 /24 | 20 | End device — VLAN 20 |
| PC3 | NIC | 192.168.30.10 /24 | 30 | End device — VLAN 30 |
3. Step 1 — Configure the Switch
The switch needs three things: VLANs created, access ports assigned, and the uplink to the router configured as a trunk. This builds directly on previous labs — commands are shown in full for completeness.
NetsTuts_SW1>en NetsTuts_SW1#conf t Enter configuration commands, one per line. End with CNTL/Z. ! ── Create VLANs ────────────────────────────────────────── NetsTuts_SW1(config)#vlan 10 NetsTuts_SW1(config-vlan)#name SALES NetsTuts_SW1(config-vlan)#vlan 20 NetsTuts_SW1(config-vlan)#name HR NetsTuts_SW1(config-vlan)#vlan 30 NetsTuts_SW1(config-vlan)#name IT NetsTuts_SW1(config-vlan)#vlan 999 NetsTuts_SW1(config-vlan)#name NATIVE-UNUSED NetsTuts_SW1(config-vlan)#exit ! ── Assign access ports ─────────────────────────────────── NetsTuts_SW1(config)#interface FastEthernet0/1 NetsTuts_SW1(config-if)#description PC1-VLAN10 NetsTuts_SW1(config-if)#switchport mode access NetsTuts_SW1(config-if)#switchport access vlan 10 NetsTuts_SW1(config-if)#exit NetsTuts_SW1(config)#interface FastEthernet0/2 NetsTuts_SW1(config-if)#description PC2-VLAN20 NetsTuts_SW1(config-if)#switchport mode access NetsTuts_SW1(config-if)#switchport access vlan 20 NetsTuts_SW1(config-if)#exit NetsTuts_SW1(config)#interface FastEthernet0/3 NetsTuts_SW1(config-if)#description PC3-VLAN30 NetsTuts_SW1(config-if)#switchport mode access NetsTuts_SW1(config-if)#switchport access vlan 30 NetsTuts_SW1(config-if)#exit ! ── Configure trunk uplink to router ───────────────────── NetsTuts_SW1(config)#interface GigabitEthernet0/1 NetsTuts_SW1(config-if)#description Trunk-to-NetsTuts_R1 NetsTuts_SW1(config-if)#switchport trunk encapsulation dot1q NetsTuts_SW1(config-if)#switchport mode trunk NetsTuts_SW1(config-if)#switchport nonegotiate NetsTuts_SW1(config-if)#switchport trunk allowed vlan 10,20,30 NetsTuts_SW1(config-if)#switchport trunk native vlan 999 NetsTuts_SW1(config-if)#end NetsTuts_SW1#wr Building configuration... [OK] NetsTuts_SW1#
4. Step 2 — Enable the Physical Interface on the Router
The physical interface (Gi0/0) must be enabled with no shutdown
but must not have an IP address assigned to it. All IP addressing goes
on the subinterfaces. Assigning an IP to the physical interface is a common mistake
that causes routing confusion.
NetsTuts_R1>en NetsTuts_R1#conf t Enter configuration commands, one per line. End with CNTL/Z. NetsTuts_R1(config)#interface GigabitEthernet0/0 NetsTuts_R1(config-if)#description Trunk-to-NetsTuts_SW1 NetsTuts_R1(config-if)#no shutdown NetsTuts_R1(config-if)#exit
5. Step 3 — Configure Subinterfaces
Create one subinterface per VLAN. Each subinterface needs two commands:
encapsulation dot1q [vlan-id] to associate it with a specific VLAN,
and ip address to assign the default gateway IP for that VLAN.
Subinterface Naming Convention
The subinterface number (e.g., .10 in Gi0/0.10) does not
have to match the VLAN ID — but matching them is a universal best practice that makes
the configuration self-documenting and easier to troubleshoot.
Configuring Subinterfaces for VLANs 10, 20, and 30
! ── Subinterface for VLAN 10 (SALES) ───────────────────── NetsTuts_R1(config)#interface GigabitEthernet0/0.10 NetsTuts_R1(config-subif)#description Gateway-VLAN10-SALES NetsTuts_R1(config-subif)#encapsulation dot1q 10 NetsTuts_R1(config-subif)#ip address 192.168.10.1 255.255.255.0 NetsTuts_R1(config-subif)#exit ! ── Subinterface for VLAN 20 (HR) ──────────────────────── NetsTuts_R1(config)#interface GigabitEthernet0/0.20 NetsTuts_R1(config-subif)#description Gateway-VLAN20-HR NetsTuts_R1(config-subif)#encapsulation dot1q 20 NetsTuts_R1(config-subif)#ip address 192.168.20.1 255.255.255.0 NetsTuts_R1(config-subif)#exit ! ── Subinterface for VLAN 30 (IT) ──────────────────────── NetsTuts_R1(config)#interface GigabitEthernet0/0.30 NetsTuts_R1(config-subif)#description Gateway-VLAN30-IT NetsTuts_R1(config-subif)#encapsulation dot1q 30 NetsTuts_R1(config-subif)#ip address 192.168.30.1 255.255.255.0 NetsTuts_R1(config-subif)#exit NetsTuts_R1(config)#end NetsTuts_R1#wr Building configuration... [OK] NetsTuts_R1#
(config-subif)# when inside a subinterface.
Subinterface Command Breakdown
| Command | What It Does | Why It Matters |
|---|---|---|
interface GigabitEthernet0/0.10 |
Creates subinterface .10 on the physical Gi0/0 interface | The .10 suffix is the subinterface number — match it to the VLAN ID for clarity |
description Gateway-VLAN10-SALES |
Labels the subinterface for documentation | Essential in production — makes the purpose of each subinterface immediately clear |
encapsulation dot1q 10 |
Associates this subinterface with VLAN 10 — the router will process frames tagged with VLAN 10 on this subinterface | This is the binding between the subinterface and the VLAN — without it, the router ignores tagged frames for this VLAN |
ip address 192.168.10.1 255.255.255.0 |
Assigns the default gateway IP for the VLAN 10 subnet | All PCs in VLAN 10 must set this as their default gateway |
encapsulation dot1q 999 native on the corresponding
subinterface. The native keyword tells the router that frames on this
subinterface arrive untagged:
NetsTuts_R1(config)#interface GigabitEthernet0/0.999
NetsTuts_R1(config-subif)#encapsulation dot1q 999 native
NetsTuts_R1(config-subif)#exit
6. Complete Router Configuration
! ══════════════════════════════════════════════════════════ ! NetsTuts Router-on-a-Stick Baseline — NetsTuts_R1 ! ══════════════════════════════════════════════════════════ NetsTuts_R1>en NetsTuts_R1#conf t Enter configuration commands, one per line. End with CNTL/Z. ! ── Enable physical interface (no IP address) ───────────── NetsTuts_R1(config)#interface GigabitEthernet0/0 NetsTuts_R1(config-if)#description Trunk-to-NetsTuts_SW1 NetsTuts_R1(config-if)#no shutdown NetsTuts_R1(config-if)#exit ! ── VLAN 10 subinterface ────────────────────────────────── NetsTuts_R1(config)#interface GigabitEthernet0/0.10 NetsTuts_R1(config-subif)#description Gateway-VLAN10-SALES NetsTuts_R1(config-subif)#encapsulation dot1q 10 NetsTuts_R1(config-subif)#ip address 192.168.10.1 255.255.255.0 NetsTuts_R1(config-subif)#exit ! ── VLAN 20 subinterface ────────────────────────────────── NetsTuts_R1(config)#interface GigabitEthernet0/0.20 NetsTuts_R1(config-subif)#description Gateway-VLAN20-HR NetsTuts_R1(config-subif)#encapsulation dot1q 20 NetsTuts_R1(config-subif)#ip address 192.168.20.1 255.255.255.0 NetsTuts_R1(config-subif)#exit ! ── VLAN 30 subinterface ────────────────────────────────── NetsTuts_R1(config)#interface GigabitEthernet0/0.30 NetsTuts_R1(config-subif)#description Gateway-VLAN30-IT NetsTuts_R1(config-subif)#encapsulation dot1q 30 NetsTuts_R1(config-subif)#ip address 192.168.30.1 255.255.255.0 NetsTuts_R1(config-subif)#exit NetsTuts_R1(config)#end NetsTuts_R1#wr Building configuration... [OK] NetsTuts_R1#
7. Verification
show ip interface brief
Confirms all subinterfaces are up and have the correct IP addresses:
NetsTuts_R1#show ip interface brief Interface IP-Address OK? Method Status Protocol GigabitEthernet0/0 unassigned YES unset up up GigabitEthernet0/0.10 192.168.10.1 YES manual up up GigabitEthernet0/0.20 192.168.20.1 YES manual up up GigabitEthernet0/0.30 192.168.30.1 YES manual up up
show ip route
Confirms the router has automatically learned connected routes for all three VLAN subnets — no static routes needed:
NetsTuts_R1#show ip route
Codes: C - connected, S - static, R - RIP, O - OSPF
192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.10.0/24 is directly connected, GigabitEthernet0/0.10
L 192.168.10.1/32 is directly connected, GigabitEthernet0/0.10
192.168.20.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.20.0/24 is directly connected, GigabitEthernet0/0.20
L 192.168.20.1/32 is directly connected, GigabitEthernet0/0.20
192.168.30.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.30.0/24 is directly connected, GigabitEthernet0/0.30
L 192.168.30.1/32 is directly connected, GigabitEthernet0/0.30
show running-config | section interface
NetsTuts_R1#show running-config | section interface interface GigabitEthernet0/0 description Trunk-to-NetsTuts_SW1 no ip address no shutdown ! interface GigabitEthernet0/0.10 description Gateway-VLAN10-SALES encapsulation dot1Q 10 ip address 192.168.10.1 255.255.255.0 ! interface GigabitEthernet0/0.20 description Gateway-VLAN20-HR encapsulation dot1Q 20 ip address 192.168.20.1 255.255.255.0 ! interface GigabitEthernet0/0.30 description Gateway-VLAN30-IT encapsulation dot1Q 30 ip address 192.168.30.1 255.255.255.0 !
Test Inter-VLAN Connectivity with ping
From the router, ping each PC to confirm end-to-end reachability across VLANs:
NetsTuts_R1#ping 192.168.10.10 !!!!! Success rate is 100 percent (5/5) NetsTuts_R1#ping 192.168.20.10 !!!!! Success rate is 100 percent (5/5) NetsTuts_R1#ping 192.168.30.10 !!!!! Success rate is 100 percent (5/5)
Extended ping from PC1 to PC2 (Cross-VLAN)
PC1> ping 192.168.20.10 84 bytes from 192.168.20.10 icmp_seq=1 ttl=127 time=2.345 ms 84 bytes from 192.168.20.10 icmp_seq=2 ttl=127 time=1.891 ms 84 bytes from 192.168.20.10 icmp_seq=3 ttl=127 time=2.102 ms
Verification Command Summary
| Command | What It Confirms |
|---|---|
show ip interface brief |
All subinterfaces are up/up with correct IPs — physical interface shows unassigned |
show ip route |
Connected routes exist for all VLAN subnets |
show interfaces GigabitEthernet0/0.10 |
Subinterface details including encapsulation VLAN ID |
show running-config | section interface |
Full subinterface configuration with encapsulation and IP |
show vlan brief (on switch) |
Confirms VLANs exist and access ports are assigned correctly |
show interfaces trunk (on switch) |
Confirms trunk is operational and all required VLANs are allowed and active |
ping cross-VLAN |
End-to-end test — TTL of 127 confirms one router hop (inter-VLAN routing working) |
8. Troubleshooting Router-on-a-Stick
| Problem | Symptom | Cause | Fix |
|---|---|---|---|
| Subinterface down/down | show ip interface brief shows subinterface down |
Physical interface not enabled — no shutdown missing on Gi0/0 |
Enter interface GigabitEthernet0/0 and run no shutdown |
| No inter-VLAN routing | Ping fails between VLANs — router unreachable | PC default gateway not set, or set to wrong IP | Verify PC default gateway matches the subinterface IP for that VLAN |
| One VLAN works, others don't | PC1 can ping router but PC2 cannot | Missing or wrong encapsulation dot1q [vlan-id] on a subinterface |
Check show running-config | section interface — verify each subinterface has the correct VLAN ID in encapsulation dot1q |
| Trunk not carrying VLAN traffic | Cross-VLAN pings fail — router pings succeed locally | VLAN not in trunk allowed list on switch, or VLAN not created on switch | Check show interfaces trunk on the switch — verify the VLAN is in "allowed and active" |
| IP address on physical interface | Routing works for one subnet but fails for others | IP address accidentally assigned to Gi0/0 instead of subinterfaces |
Remove it: no ip address on the physical interface. IPs belong on subinterfaces only. |
| Wrong VLAN encapsulation | Traffic goes to wrong VLAN | Subinterface VLAN ID does not match the switch access port VLAN | Verify encapsulation dot1q [id] on each subinterface matches the corresponding VLAN on the switch. Cross-check with show vlan brief on the switch. |
Key Points & Exam Tips
- Router-on-a-Stick uses a single physical trunk link and subinterfaces (one per VLAN) to route between VLANs — no additional physical interfaces needed.
- The physical interface must have
no shutdownbut no IP address. All IPs go on the subinterfaces. - Each subinterface requires
encapsulation dot1q [vlan-id]before an IP address — without it, the router will not process tagged frames for that VLAN. See 802.1Q VLAN Tagging for the tagging standard. - The subinterface number does not have to match the VLAN ID — but always match them (e.g.,
Gi0/0.10for VLAN 10) for clarity and consistency. - The switch port connecting to the router must be a trunk port — not an access port. Verify with
show interfaces trunkon the switch. - Each PC's default gateway must be set to the IP address of its VLAN's subinterface — this is the most common misconfiguration in lab environments.
- A cross-VLAN ping with TTL 127 (for Windows hosts, TTL 128 − 1) confirms inter-VLAN routing is working — the packet passed through one router hop.
- The limitation of router-on-a-stick is the single physical link bottleneck — all inter-VLAN traffic must flow through one cable. For high-traffic environments, use a Layer 3 switch instead.
- For a native VLAN subinterface, add the
nativekeyword:encapsulation dot1q 999 native— this tells the router that frames on this subinterface arrive untagged. See 802.1Q VLAN Tagging for native VLAN details. - Subinterfaces are logical — they share the physical interface's bandwidth. All subinterface states depend on the physical interface state: if
Gi0/0goes down, all subinterfaces go down with it.