Skip to content
RankCore.AI
← All posts

VLANs and Inter-VLAN Routing: A Technical Guide to Router-on-a-Stick and Layer 3 Switches

· Networking, VLAN, 802.1Q, Routing, CCNA

The short video above starts in a familiar place: one office, two departments, and a manager who wants engineering and finance on separate networks — with only one switch in the rack. The answer is VLANs, and when those departments later need to exchange a file, the answer is inter-VLAN routing. This is the study version: it walks the same story in enough detail to configure, verify, and troubleshoot it, and it flags every place the two-minute video simplifies the standard.

VLANs are a layer 2 tool; moving traffic between them is a layer 3 job. For the broader stack, see our OSI model study guide.

1. What a VLAN actually is

A VLAN, or virtual LAN, is a way to split one physical switched network into multiple broadcast domains. Devices in the same VLAN can reach each other at layer 2, as if they were on their own switch. Devices in different VLANs cannot, even if their cables land on the same chassis.

That is the point of the office example. You create VLAN 10 for engineering and VLAN 20 for finance, then assign each access port to one of them. Physically it is still one switch. Logically it behaves like two. Broadcasts, unknown unicasts, and layer 2 multicasts stay inside their VLAN. A finance workstation does not see engineering ARP storms, and a compromised laptop in one department cannot simply talk to the other at layer 2.

VLANs were standardized by IEEE 802.1Q. The usable VLAN IDs are 1 through 4094. The 12-bit identifier can represent 0 to 4095, but 0 and 4095 are reserved: 0 is a priority tag with no VLAN ID, and 4095 is reserved for implementation use. Treat VLAN 1 carefully — on many platforms it is the default for unconfigured ports, which makes it a poor choice for user or management traffic.

A VLAN is not an IP subnet, but good design maps them one-to-one: VLAN 10 gets 192.168.10.0/24, VLAN 20 gets 192.168.20.0/24. The VLAN separates traffic at layer 2; the subnet is how hosts decide whether a destination is "local" or must go to a default gateway.

On the office switch, the first configuration is intentionally small:

vlan 10
 name Engineering
vlan 20
 name Finance

interface range GigabitEthernet0/1-4
 switchport mode access
 switchport access vlan 10
 switchport nonegotiate

interface range GigabitEthernet0/5-8
 switchport mode access
 switchport access vlan 20
 switchport nonegotiate

Until you add a router or an SVI, each department can reach itself. A file from 192.168.10.10 to 192.168.20.20 will not get there.

2. Access ports, trunks, and the 802.1Q tag

On a switch you will meet two everyday port roles.

An access port belongs to one VLAN. The host usually sends and receives untagged frames. The switch associates those frames with the port's VLAN and, if it forwards them onto a trunk, adds a tag.

A trunk port carries frames from many VLANs on one link. Between switches, or between a switch and a router, each frame needs a label so the far end knows which VLAN it belongs to. IEEE 802.1Q inserts a 4-byte tag between the source MAC address and the EtherType. The tag has:

  • a 16-bit Tag Protocol Identifier (TPID) of 0x8100
  • a 16-bit Tag Control Information field: 3 bits of Priority Code Point (PCP), 1 bit of Drop Eligible Indicator (DEI, formerly called CFI), and a 12-bit VLAN ID

Because the frame changes, the device recomputes the Frame Check Sequence. The standard maximum Ethernet frame grows from 1518 to 1522 bytes with the tag. Access-port hosts never have to know this; the tag lives on the trunk.

On Cisco IOS, those two roles look like this:

interface GigabitEthernet0/1
 switchport mode access
 switchport access vlan 10
 switchport nonegotiate

interface GigabitEthernet0/24
 switchport mode trunk
 switchport trunk native vlan 99
 switchport trunk allowed vlan 10,20,99
 switchport nonegotiate

VLAN 99 is an unused native VLAN, allowed on the trunk so both ends agree, with no access ports placed in it.

switchport mode access or trunk is deliberate. Leaving a port in a dynamic mode invites Dynamic Trunking Protocol (DTP) negotiation, a common source of VLAN-hopping attacks. nonegotiate turns DTP off. Restrict allowed vlan so a trunk carries only the VLANs it needs; a default of 1–4094 is wider than most links require.

The native VLAN. On an 802.1Q trunk, frames for one VLAN — the native VLAN — are sent untagged. Cisco's default is VLAN 1. Both ends of a trunk must agree; a mismatch produces a broken or leaky trunk. Set the native VLAN to an unused VLAN that carries no user data, and do not use VLAN 1 for hosts.

Nuance on the video: "Assign each switch port to a VLAN" is easy to picture as access ports on a single switch. In a real building, a VLAN usually spans many switches. Engineering ports on floor 2 and floor 5 are still VLAN 10; trunks between the switches carry the tagged frames. One switch is the teaching example, not the architecture.

3. What a layer 2 switch will and will not do

Inside VLAN 10, engineering talks to engineering. The switch learns MAC addresses per VLAN, floods broadcasts only in that VLAN, and forwards unicasts only to ports in that VLAN. The same happens independently in VLAN 20.

Between VLANs, a pure layer 2 switch does not forward. There is no layer 2 path from VLAN 10 to VLAN 20. That isolation is the security win the video describes.

Nuance on "blocks traffic completely": That is true of correct layer 2 forwarding, not a magical air gap. Hosts in different VLANs are also almost always in different IP subnets, so they would not talk at layer 3 without a gateway anyway. Misconfiguration can punch holes: a trunk allowed-list that is too wide, a native-VLAN mismatch, DTP turning an access port into a trunk, or double-tagging against the native VLAN. Isolation is only as strong as the port configuration. ACLs on the router or SVI later restrict which inter-VLAN conversations are allowed.

When engineering needs to send a file to finance, you need a layer 3 device with an interface — physical or virtual — in each VLAN, that will route between those subnets. That is inter-VLAN routing.

Cisco's Switching, Routing, and Wireless Essentials material (CCNAv7) lists three common methods. The video covers the two you will actually design for today. The third, worth knowing for exams, is legacy inter-VLAN routing: one physical router interface per VLAN, each cabled to a matching access port. It works, and it wastes ports and cables, so it has largely been replaced by the two methods below.

4. Method one: router-on-a-stick

A router-on-a-stick uses one physical router interface, connected to a switch trunk, and splits that interface into subinterfaces. Each subinterface handles one VLAN, has its own IP address, and becomes the default gateway for that VLAN's hosts.

On the switch, the port facing the router is a trunk. On the router, you create GigabitEthernet0/0.10 and GigabitEthernet0/0.20. The .10 and .20 suffixes are a naming convention, not the thing that binds the VLAN. The command that does the binding is encapsulation dot1Q.

interface GigabitEthernet0/0
 no shutdown

interface GigabitEthernet0/0.10
 description Gateway for VLAN 10 Engineering
 encapsulation dot1Q 10
 ip address 192.168.10.1 255.255.255.0

interface GigabitEthernet0/0.20
 description Gateway for VLAN 20 Finance
 encapsulation dot1Q 20
 ip address 192.168.20.1 255.255.255.0

Each subinterface needs an address on a unique subnet. Enable the parent interface with no shutdown; if it is down, every subinterface is down. The router does not need a routing protocol to move packets between these directly connected subnets. They appear in show ip route as connected routes, each exiting through its subinterface.

Follow one packet

PC-Eng at 192.168.10.10 sends a file to PC-Fin at 192.168.20.20.

  1. PC-Eng sees that 192.168.20.20 is not in 192.168.10.0/24, so the packet must go to the default gateway 192.168.10.1. It ARPs for that gateway's MAC address.
  2. It sends an Ethernet frame to the gateway MAC. The IP destination is still PC-Fin. The frame leaves the access port untagged.
  3. The switch associates the frame with VLAN 10, adds an 802.1Q tag with VID 10, and sends it out the trunk to the router.
  4. The router accepts the tagged frame on G0/0.10, strips the tag, and looks up the destination IP. 192.168.20.0/24 is connected on G0/0.20.
  5. The router ARPs in VLAN 20 for PC-Fin if needed, then builds a new frame: destination MAC of PC-Fin, source MAC of the VLAN 20 subinterface, 802.1Q tag with VID 20. Routing does not just retag the old frame.
  6. The switch receives the VLAN 20 frame on the trunk, removes the tag, and sends an untagged frame out the finance access port.

The file went up the trunk and came back down the same cable, exactly as the video says. A useful check on the host: a same-VLAN ping usually returns with the TTL you sent; a routed ping comes back with a TTL that is one lower, because the router decremented it. This path is a layer 3 hop, not a layer 2 shortcut.

That shared cable is why the design is cheap and simple, and why that one link — and that one router interface — can become a bottleneck and a single point of failure. Every inter-VLAN packet traverses the link twice, once in each VLAN. A 1 Gb/s trunk has to share that capacity among all VLANs. For a lab, a branch, or a small office, that is often fine. For a busy campus core, it is the wrong tool.

Correction on the video: It says "each frame gets an 802.1 Q tag." The standard is written 802.1Q, and access-port frames are usually untagged. The tag is added when the frame enters a trunk. Also, G0/0.10 does not, by itself, mean VLAN 10. Always set encapsulation dot1Q 10. Matching the subinterface number to the VLAN ID is a courtesy to the next engineer.

5. Method two: a layer 3 switch and SVIs

A layer 3, or multilayer, switch can forward Ethernet frames and route IP packets. You still create VLAN 10 and VLAN 20 and assign the access ports. Instead of cabling a router, you create a switch virtual interface (SVI) for each VLAN, give it the gateway address, and enable IP routing.

vlan 10
 name Engineering
vlan 20
 name Finance

interface GigabitEthernet0/1
 switchport mode access
 switchport access vlan 10

interface GigabitEthernet0/5
 switchport mode access
 switchport access vlan 20

ip routing

interface Vlan10
 ip address 192.168.10.1 255.255.255.0
 no shutdown

interface Vlan20
 ip address 192.168.20.1 255.255.255.0
 no shutdown

interface Vlan10 is not an access port and does not move a host into VLAN 10. It is a virtual layer 3 interface that lives inside the switch and owns the gateway address for that VLAN. ip routing is the Cisco IOS command that turns on layer 3 forwarding; without it, the switch may have SVIs for management and still refuse to route between them. Other vendors use different syntax for the same idea.

On a multilayer platform, that routing decision is typically made in hardware, which is why the video calls it much faster than router-on-a-stick. The packet never has to leave the chassis and come back on a single uplink.

Two details are easy to miss. First, not every switch is a layer 3 switch. A layer 2 access switch can have an SVI for management and still be unable to route. Hardware, software, and licensing all matter. Second, an SVI is only up if the VLAN exists, the SVI is not shut down, and — under the usual autostate rules — at least one port in that VLAN is up and forwarding. An SVI with no active ports will go down, and hosts will lose their gateway.

Multilayer switches can also take a physical port out of switching and make it a routed port (no switchport on Cisco IOS, then an IP address on the port itself). Use an SVI when the gateway should serve a VLAN with many access ports. Use a routed port for a point-to-point uplink when you do not want that link in a VLAN or in Spanning Tree.

6. How to choose

  1. Lab, small office, or a layer 2-only switch already in the rack? Router-on-a-stick is the straightforward answer. You add a router (or a router interface on a firewall), configure a trunk, and you are routing.
  2. Campus, data center, or any place inter-VLAN traffic is a normal part of the day? Use a layer 3 switch and SVIs, or routed (layer 3) ports and upstream routers. The packet stays in hardware, and you are not funnelling every department-to-department flow through one cable.
  3. Need to filter what finance can reach in engineering? Routing alone is not a security policy. Put ACLs on the SVIs or router subinterfaces, or use a firewall as the inter-VLAN gateway when the boundary matters.
  4. Building a larger fabric? Many modern designs push routing toward the access or distribution layer and use routed uplinks rather than a wide layer 2 trunk into a single router. The two methods in the video are still the foundation.

Do not give a router-on-a-stick gateway and an SVI the same IP for the same VLAN. Two devices claiming 192.168.10.1 will fight. Pick one gateway per subnet.

7. Security and design pitfalls

VLANs isolate broadcast domains. They do not replace authentication, patching, or a firewall. A few configurations are worth making habitual:

  • Do not use VLAN 1 for user or management traffic. Unconfigured ports often start there.
  • Disable DTP. Set the mode explicitly and use switchport nonegotiate. An attacker who coaxes a port into becoming a trunk can see every VLAN that trunk allows.
  • Change the native VLAN to an unused ID and prune it from user trunks. Double-tagging attacks rely on a predictable, used native VLAN.
  • Allow only the VLANs you need on each trunk.
  • Put a filter on the gateway. Once inter-VLAN routing is on, engineering can reach finance unless you write a policy that says otherwise.
  • Assign unused ports to a black-hole VLAN, shut them, and keep them off the user trunks.

8. Verification

Work from the host outward. Confirm the PC has the right address, mask, and default gateway (ipconfig on Windows, ip addr and ip route on Linux). Ping the gateway first, then a host in the other VLAN.

On a Cisco router or layer 3 switch, these commands do most of the work:

show ip route
show ip interface brief
show interfaces trunk
show vlan brief
show interfaces GigabitEthernet0/0.10

show ip route should list each VLAN subnet as a connected route. show interfaces trunk should show the link to the router (or the inter-switch trunks) in a trunking state, with the expected VLANs allowed and active, and with a matching native VLAN on both ends. show vlan brief confirms that VLAN 10 and VLAN 20 exist and lists their access ports.

A short checklist when a ping fails:

  • The host's gateway IP does not match the subinterface or SVI.
  • The encapsulation VLAN does not match the access VLAN (the .10 suffix fooled someone).
  • The physical parent interface is shut, so every subinterface is down.
  • ip routing is missing on the layer 3 switch.
  • The SVI is down because autostate has no active port in that VLAN.
  • The trunk is not trunking, or the VLAN is missing from allowed vlan.
  • A native-VLAN mismatch is dropping or leaking frames.
  • An ACL on the gateway is refusing the traffic you are testing.

9. A short lab

Build the office in a simulator or on two devices: a layer 2 switch plus a router for router-on-a-stick, then the same VLANs on a layer 3 switch with SVIs and no external router.

  1. Create VLAN 10 and VLAN 20, name them, and assign access ports. Confirm with show vlan brief.
  2. Addressing: PC-Eng 192.168.10.10/24 gateway 192.168.10.1; PC-Fin 192.168.20.20/24 gateway 192.168.20.1.
  3. Configure the trunk and the two router subinterfaces. Enable the parent interface. Confirm connected routes with show ip route.
  4. Ping the gateway, then the far host. If the second ping fails, work through the checklist in section 8.
  5. Tear the router off and configure SVIs plus ip routing on a layer 3 switch. Ping again. Compare show ip route and notice there is no external trunk to a router.

If you can do those five steps without notes, you have the video at working depth.

10. FAQ

Can two VLANs use the same IP subnet? Not if you want them to route to each other in the usual way. A router routes between networks. Give each VLAN its own subnet.

Do I need VLANs if I already have a firewall? Yes, often. The firewall is the policy point; the VLAN is how you deliver a department, a guest network, or a camera network to that firewall on a trunk. They solve different problems.

Is a layer 3 switch just a router? It is a switch that can also route. It still learns MAC tables and builds VLANs. The SVI is the router interface for a VLAN. Many platforms also support routed physical ports, which are layer 3 interfaces that are not tied to a VLAN.

Why did my SVI go down when I unplugged the last access port? Autostate. The virtual interface follows the VLAN's data-plane state. Leave a trunk up that carries the VLAN, or disable autostate only if you understand the side effects.

Does router-on-a-stick still matter if everyone uses layer 3 switches? Yes, in labs, in small sites, and on exams. It is also the cleanest way to see, on the wire, what a VLAN tag and a gateway actually do.

Why can I ping inside my VLAN but not the other department? Same-VLAN success means the access port, VLAN, and addressing are probably fine. Inter-VLAN failure is almost always the gateway: a wrong default gateway on the PC, a shut parent interface, a missing encapsulation dot1Q, a missing ip routing, a down SVI, or a trunk that does not allow the VLAN.

11. Interview questions

"What is a VLAN?" A broadcast domain defined by configuration, not by a separate physical switch. Isolation is at layer 2. Communication between VLANs requires a layer 3 gateway.

"How does router-on-a-stick work?" One router interface is a trunk. Subinterfaces, each with encapsulation dot1Q and a gateway address, route between the VLAN subnets. Traffic goes up the trunk and back down the same link. The cost is simplicity; the limit is that link's bandwidth and the single point of failure.

"How is that different from an SVI?" An SVI is a virtual layer 3 interface on a multilayer switch. Routing happens inside the switch, usually in hardware, with no external router hop. You still need ip routing (or the vendor equivalent), and the SVI stays up only if the VLAN is active.

12. Summary

  • A VLAN splits one physical switched network into separate layer 2 broadcast domains. The usual design maps one VLAN to one IP subnet.
  • Access ports carry a single VLAN, usually untagged. Trunks carry many VLANs, tagged with IEEE 802.1Q (TPID 0x8100, a 12-bit VLAN ID). Usable IDs are 1–4094.
  • A layer 2 switch does not forward between VLANs. That isolation is real, but it is only as strong as the trunk and access-port configuration.
  • Inter-VLAN routing is the layer 3 path between those subnets.
  • Router-on-a-stick uses an external router, a trunk, and subinterfaces. It is cheap and clear, and the shared cable can become a bottleneck.
  • A layer 3 switch uses an SVI per VLAN and routes inside the chassis, typically in hardware.
  • Set port modes explicitly, keep VLAN 1 and the native VLAN out of user traffic, allow only the VLANs a trunk needs, and put a policy on the gateway.

Follow @rankcore.ai on Instagram, and read more on blog.rankcore.ai.

Want to go deeper?

Our step-by-step video courses turn these ideas into results.

See courses

Comments

Sign in or create a free account to join the discussion.

No comments yet — be the first.