Skip to content

Intermediate · Switching and VLANs · topic 23 of 57 · 35 min

Inter-VLAN routing

Explanation

Devices in different VLANs are in different subnets, so a layer 3 device must route between them. Router-on-a-stick uses one router port as a trunk, with one subinterface per VLAN (encapsulation dot1Q 10 and an IP address). A layer 3 switch does the same job faster with SVIs (interface vlan 10) after ip routing. Each SVI or subinterface address is the default gateway for its VLAN.

Why VLANs need a router

Each VLAN is its own broadcast domain and its own IP subnet. When PC A in VLAN 10 (10.10.10.0/24) wants to reach PC B in VLAN 20 (10.10.20.0/24), it sees that B is on a different subnet. So it sends the packet to its default gateway: the router address for its own subnet. A layer 2 switch never moves frames between VLANs on its own. Something that works at layer 3 (a router or a layer 3 switch) must route the packet into the other VLAN.

Think of it like this: VLANs are like separate departments in a government office, each behind its own counter. A citizen cannot walk from the land records counter into the tax counter. They go to the enquiry desk (the default gateway), which passes the file to the right counter. Every department has its own enquiry window, just as every VLAN has its own gateway address.

A simple plan with one subnet per VLAN and the gateway on .1:

VLANNameSubnetDefault gateway
10STAFF10.10.10.0/2410.10.10.1
20GUEST10.10.20.0/2410.10.20.1
30CCTV10.10.30.0/2410.10.30.1

Option 1: one router port per VLAN

The oldest way: connect one router interface to an access port in each VLAN. It works, but three VLANs need three router ports and three cables. With 20 VLANs it is impossible. You will mostly see it in old diagrams.

Option 2: router-on-a-stick

Router-on-a-stick (ROAS) uses a single physical link between the switch and the router, configured as a trunk. On the router you split the physical interface into subinterfaces, virtual interfaces such as g0/0.10, one per VLAN. Each subinterface is told which VLAN tag it handles and gets the gateway IP address of that VLAN.

output
R1(config)# interface gigabitEthernet 0/0
R1(config-if)# no shutdown
R1(config-if)# interface gigabitEthernet 0/0.10
R1(config-subif)# encapsulation dot1Q 10
R1(config-subif)# ip address 10.10.10.1 255.255.255.0
R1(config-subif)# interface gigabitEthernet 0/0.20
R1(config-subif)# encapsulation dot1Q 20
R1(config-subif)# ip address 10.10.20.1 255.255.255.0
R1(config-subif)# interface gigabitEthernet 0/0.99
R1(config-subif)# encapsulation dot1Q 99 native

SW1(config)# interface gigabitEthernet 0/1
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk native vlan 99
Cisco IOS: the physical interface needs no shutdown; subinterfaces follow it. The subinterface number (.10) is only a label; encapsulation dot1Q 10 is what links it to VLAN 10.

A packet from VLAN 10 to VLAN 20 travels up the trunk tagged 10, the router routes it, and it comes back down the same trunk tagged 20. This hairpin is why ROAS is cheap but limited: all inter-VLAN traffic shares one link, and the router is a single point of failure.

Option 3: a layer 3 switch with SVIs

A layer 3 switch (also called a multilayer switch) can route as well as switch, in hardware, at full speed. You give each VLAN a Switched Virtual Interface (SVI): a virtual interface named interface vlan 10 that acts as the gateway for that VLAN. Routing between SVIs is turned on with ip routing.

output
DSW1(config)# ip routing
DSW1(config)# interface vlan 10
DSW1(config-if)# ip address 10.10.10.1 255.255.255.0
DSW1(config-if)# no shutdown
DSW1(config-if)# interface vlan 20
DSW1(config-if)# ip address 10.10.20.1 255.255.255.0
DSW1(config-if)# no shutdown
Cisco IOS: two SVIs act as the gateways for VLANs 10 and 20. show ip route then shows both subnets as connected (C).

An SVI comes up (up/up) only when the VLAN exists on the switch, at least one access or trunk port in that VLAN is up and forwarding, and the SVI itself is not shut down. If an SVI is stuck down, check those three things.

Routed ports

A port on a layer 3 switch can also behave like a router port. no switchport turns it into a routed port: it belongs to no VLAN and takes an IP address directly. Routed ports are used for links to a router, a firewall or another layer 3 switch.

output
DSW1(config)# interface gigabitEthernet 1/0/24
DSW1(config-if)# no switchport
DSW1(config-if)# ip address 10.0.0.1 255.255.255.252
Cisco IOS: a routed uplink from the layer 3 switch to the internet router.

Which option to choose

MethodGoodNot so good
Router-on-a-stickCheap, needs only one router portOne link carries all inter-VLAN traffic; slower; single point of failure
Layer 3 switch SVIsVery fast hardware routing; scales to many VLANsCosts more than a layer 2 switch

Common mistakes and how to fix them

  • Forgetting ip routing on the layer 3 switch: the SVIs come up, but nothing is routed between them.
  • Forgetting no shutdown on the router physical interface: every subinterface stays down.
  • Wrong VLAN number in encapsulation dot1Q: the subinterface listens for the wrong tag.
  • The switch port facing the router is left as an access port instead of a trunk.
  • A PC with the wrong default gateway, for example the VLAN 10 PC pointing at 10.10.20.1.
Careful: When inter-VLAN pings fail, test in order: can the PC ping its own gateway? Does show ip interface brief show the subinterface or SVI up/up? Does show ip route list both subnets as connected? Fix the first step that fails.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Inter-VLAN routing · 1/7

Inter-VLAN routing

In this lesson you will learn how traffic moves from one VLAN to another.

Prefer a video by a teacher? Find free videos on “inter vlan routing router on a stick svi layer 3 switch packet tracer” on YouTube ↗

In real life: A college campus in Chennai

An engineering college has VLANs for faculty, students, labs and the library. In the first year they used router-on-a-stick on a small branch router, and at exam time, when 400 students uploaded projects to the faculty file server, the single trunk to the router was full. They replaced the core with a layer 3 switch: SVIs for each VLAN, ip routing, and a routed port to the firewall. Inter-VLAN traffic now stays inside the switch hardware, and the router only handles internet traffic.

output
ip routing
interface vlan 10
 description FACULTY
 ip address 172.16.10.1 255.255.255.0
interface vlan 20
 description STUDENTS
 ip address 172.16.20.1 255.255.255.0
interface gigabitEthernet 1/0/48
 no switchport
 ip address 172.16.255.1 255.255.255.252
Cisco IOS: SVIs for each VLAN and a routed port to the firewall.

Practice (0/4 done)

Task 1 · Question

On router-on-a-stick, which line ties subinterface g0/0.30 to VLAN 30?

Task 2 · Code · Python

Write gateway_for(host_ip, gateways) where gateways is a dict like {10: "10.10.10.1/24", 20: "10.10.20.1/24"}: VLAN number to the gateway address with its prefix length. Return the gateway IP (without the prefix) whose subnet contains host_ip, or None if no VLAN subnet contains it. Use the ipaddress module.

Task 3 · Practice

Packet Tracer lab, router-on-a-stick: one 2911 router (R1), one 2960 switch (SW1), PC1 in VLAN 10 (10.10.10.10/24) and PC2 in VLAN 20 (10.10.20.10/24). Connect R1 g0/0 to SW1 g0/1. Configure the VLANs, the access ports, the trunk and the router subinterfaces so that PC1 can ping PC2.

Task 4 · Practice

Packet Tracer lab, layer 3 switch: replace R1 in the previous lab with a 3650 multilayer switch (DSW1) that has VLANs 10 and 20 and the two PCs connected directly. Configure SVIs so that PC1 can ping PC2, and add a routed port g1/0/24 with address 10.0.0.1/30 toward an internet router.

Quick quiz

Question 1

1.A PC in VLAN 10 sends a packet to a PC in VLAN 20. Where does it send the frame first?

Question 2

2.Which command lets a layer 3 switch route between its SVIs?

Question 3

3.An SVI for VLAN 30 stays down/down. Which is a likely cause?

Question 4

4.What is the main weakness of router-on-a-stick?

Question 5

5.What does no switchport do on a layer 3 switch port?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

A PC in VLAN 10 sends a packet to a PC in VLAN 20. Where does it send the frame first?

Answer: To its default gateway

The other PC is on a different subnet, so the PC sends the packet to its default gateway, which routes it.

Which command lets a layer 3 switch route between its SVIs?

Answer: ip routing

ip routing turns on IP routing; without it the SVIs only act as management addresses.

An SVI for VLAN 30 stays down/down. Which is a likely cause?

Answer: No port in VLAN 30 is up

An SVI needs the VLAN to exist and at least one up, forwarding port in that VLAN.

What is the main weakness of router-on-a-stick?

Answer: All inter-VLAN traffic shares one link to one router

Every packet between VLANs goes up and down the same trunk, which can become a bottleneck and a single point of failure.

What does no switchport do on a layer 3 switch port?

Answer: Makes it a routed port that can take an IP address

no switchport turns the port into a layer 3 routed port, like a router interface.

An IP phone and a PC share one switch port. Which command puts the phone traffic in VLAN 50?Related

Answer: switchport voice vlan 50

switchport voice vlan 50 tells the phone to tag voice frames with VLAN 50; the PC stays in the access VLAN.

From VLANs: what they are and why we use them

How are frames in the native VLAN sent on an 802.1Q trunk?Related

Answer: Untagged

The native VLAN is the one VLAN whose frames cross the trunk without a tag.

From Trunks and 802.1Q tagging

Which command gives a layer 2 switch a gateway for its own management traffic?Related

Answer: ip default-gateway 10.99.0.1

A layer 2 switch does not route, so it uses ip default-gateway, like a PC.

From Switch management and interface troubleshooting

A frame to ffff.ffff.ffff arrives on port 5 of a 24-port switch (all in one VLAN). Where does it go?Related

Answer: All ports except port 5

Broadcasts are flooded out of every port except the incoming one.

From How a switch learns and forwards

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 2 more topics in “Switching and VLANs” before its exam: CDP and LLDP: discovering neighbours, Switch management and interface troubleshooting.
  2. Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.

← Previous: Trunks and 802.1Q tagging