Intermediate · Switching and VLANs · topic 23 of 57 · 35 min
Inter-VLAN routing
Explanation
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.
A simple plan with one subnet per VLAN and the gateway on .1:
| VLAN | Name | Subnet | Default gateway |
|---|---|---|---|
| 10 | STAFF | 10.10.10.0/24 | 10.10.10.1 |
| 20 | GUEST | 10.10.20.0/24 | 10.10.20.1 |
| 30 | CCTV | 10.10.30.0/24 | 10.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.
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 99A 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.
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 shutdownAn 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.
DSW1(config)# interface gigabitEthernet 1/0/24
DSW1(config-if)# no switchport
DSW1(config-if)# ip address 10.0.0.1 255.255.255.252Which option to choose
| Method | Good | Not so good |
|---|---|---|
| Router-on-a-stick | Cheap, needs only one router port | One link carries all inter-VLAN traffic; slower; single point of failure |
| Layer 3 switch SVIs | Very fast hardware routing; scales to many VLANs | Costs 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.
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
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.
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.252Practice (0/4 done)
On router-on-a-stick, which line ties subinterface g0/0.30 to VLAN 30?
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.
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.
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
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- CDP and LLDP: discovering neighboursSwitching and VLANs · same module
- TCP/IP and the network layersCyber Security: from zero to SOC analyst · Networking for security
- Layer 2 security: port security, DHCP snooping, DAINetwork security
- Network devicesHow networks work
- Troubleshooting tools and common faultsTroubleshooting and the CCNA exam
- How a router forwards: the routing tableRouting: static routes and OSPF
Questions people ask about this
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.
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.
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.
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.
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
- 2 more topics in “Switching and VLANs” before its exam: CDP and LLDP: discovering neighbours, Switch management and interface troubleshooting.
- Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.