How-toNetworking

Router-on-a-Stick in GNS3: VLAN & Subinterface Lab

Technical Terrence · for the office and home

Intro

Router-on-a-stick is a simple way to route between VLANs when the switch is Layer 2 only. The switch keeps each VLAN’s traffic separate. One trunk cable carries those VLANs, tagged with IEEE 802.1Q, to a router. The router uses a subinterface for each VLAN, strips or adds the tag, and routes between the subnets.

It is called “on a stick” because a single physical link does the job of several. In production, a Layer 3 switch or a firewall often replaces this design. In a lab, it is still the clearest way to see tagging, trunks, and default gateways on the same page.

This walkthrough builds that lab in GNS3: one router, one Layer 2 switch, and two PCs in different VLANs. You will create the VLANs, make the switch-to-router link a trunk, configure encapsulation dot1Q on the router subinterfaces, set default gateways, and test inter-VLAN routing. A later section covers the usual mistakes, including a native VLAN mismatch and a missing no shutdown.

This is a lab on your computer, not a change to a live office or home network.

PC1 in VLAN 10 and PC2 in VLAN 20 on a switch, with one 802.1Q trunk to a router and subinterfaces .10 and .20 as the gateways.

What you need

Item What it’s for
GNS3 The GNS3 all-in-one GUI, installed from gns3.com.
The GNS3 VM (recommended) Official GNS3 docs recommend the GNS3 VM for QEMU appliances such as Cisco IOSv and IOSvL2, and do not recommend running those images on a local Windows or macOS install alone.
A Cisco router image you are licensed to use GNS3 does not include Cisco IOS. Import an image you already have a right to use (for example, an image from a Cisco Modeling Labs / CML license, or another licensed source). This guide uses a typical IOSv-style router as the example.
A Layer 2 switch image you are licensed to use IOSvL2 (or another Cisco L2 image) is the best fit, because you configure VLANs and trunks in IOS.
Two VPCS nodes Virtual PCs that come with GNS3. Enough to ping.

If you only have an older Dynamips IOS image, the same ideas apply; the interface names may be FastEthernet instead of GigabitEthernet. Use show ip interface brief on the device in front of you, not the names in this example, if they differ.

Do not use a leaked or “downloaded from a forum” IOS image. This guide will not point you to one.

Lab plan

We will use two data VLANs and leave VLAN 1 alone.

VLAN Name Subnet Gateway (router) PC address
10 Users 192.168.10.0/24 192.168.10.1 PC1: 192.168.10.10
20 Servers 192.168.20.0/24 192.168.20.1 PC2: 192.168.20.20

Cabling (once the nodes are in the workspace):

  • PC1 Ethernet0 → Switch GigabitEthernet0/1 (access, VLAN 10)
  • PC2 Ethernet0 → Switch GigabitEthernet0/2 (access, VLAN 20)
  • Router GigabitEthernet0/0 → Switch GigabitEthernet0/0 (trunk)

If your image numbers ports differently, pick any three switch ports and write them down. The commands below assume the mapping in this table.

A GNS3-style topology with R1, SW1, PC1, and PC2. Links are labeled with port names and with VLAN 10, VLAN 20, or trunk.

Set up GNS3 and the images

  1. Install GNS3 and, for IOSv or IOSvL2, add the GNS3 VM as in the official setup wizard.
  2. Import the appliance templates from the GNS3 marketplace (File > Import appliance, or the equivalent in your version), then add your image files when the wizard asks for them. Set RAM and adapters as the template recommends.
  3. Confirm the router and the L2 switch appear in the device list and can start in a new project.

A built-in GNS3 “Ethernet switch” can also tag VLANs from its node configuration window. It is fine for a quick demo, but it will not teach you the IOS trunk commands. This walkthrough uses a Cisco L2 image on purpose.

Build the topology

  1. Create a new project.
  2. Drag one router, one L2 switch, and two VPCS nodes into the workspace. Name them R1, SW1, PC1, and PC2 if you want the commands below to match the prompts.
  3. Add the three links listed in the lab plan. In GNS3 you typically use the cable/link tool, click the first device, choose the port, then click the second device and choose its port.
  4. Start all of the nodes (the green start control) and wait until the router and switch have finished booting. Open a console to each Cisco device.

On first boot you can skip the setup wizard (often by typing no) and get to a prompt. Enter privileged EXEC mode with enable, then global configuration with configure terminal.

Configure VLANs and access ports on the switch

SW1# configure terminal
SW1(config)# vlan 10
SW1(config-vlan)# name Users
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# name Servers
SW1(config-vlan)# exit

Put the PC-facing ports in the right VLAN as access ports (one VLAN, untagged):

SW1(config)# interface GigabitEthernet0/1
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 10
SW1(config-if)# no shutdown
SW1(config-if)# exit
SW1(config)# interface GigabitEthernet0/2
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
SW1(config-if)# no shutdown
SW1(config-if)# exit

Confirm with:

SW1# show vlan brief

You should see VLAN 10 and VLAN 20 active, with Gi0/1 in 10 and Gi0/2 in 20. If a port is missing, it is often still in VLAN 1, or the interface name was wrong.

The link to the router must carry both VLANs, tagged. That is a trunk.

SW1(config)# interface GigabitEthernet0/0
SW1(config-if)# switchport trunk encapsulation dot1q
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# no shutdown
SW1(config-if)# exit

About switchport trunk encapsulation dot1q: some switch images (and many older Catalyst platforms) support more than one trunk type, and they require this command before switchport mode trunk. Other images only support 802.1Q, and the encapsulation command does not exist — the switch rejects it. If that happens, skip it and set switchport mode trunk. Do not treat a rejected encapsulation command as a failed lab.

Leave the native VLAN at the default (VLAN 1 on most Cisco switches) unless you have a reason to change it. If you do change it, you must match the router side. A mismatch is one of the classic breaks in this design; see Common mistakes.

Check the trunk:

SW1# show interfaces trunk
SW1# show interfaces GigabitEthernet0/0 switchport

You want the port in trunking state, 802.1Q, with VLANs 10 and 20 allowed and active.

Access ports carry one untagged VLAN each. The trunk carries VLAN 10 and VLAN 20 tagged with 802.1Q. Native VLAN 1 is unused in this lab.

Configure router subinterfaces

The physical router port does not get an IP address in this design. Each VLAN gets a subinterface. The subinterface number is only a label; matching it to the VLAN ID (.10 for VLAN 10) is a habit that makes troubleshooting easier, not a requirement.

R1# configure terminal
R1(config)# interface GigabitEthernet0/0
R1(config-if)# no shutdown
R1(config-if)# exit
R1(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.0
R1(config-subif)# exit

Two details that matter:

  • encapsulation dot1Q 10 tells the router which VLAN tag belongs on this subinterface. Without it, the router does not know how to tag or untag, and routing between the VLANs will not work.
  • no shutdown on the physical interface brings the parent up. If the parent is down, the subinterfaces stay down with it. On some images you can also no shutdown a subinterface on its own; the parent still has to be up.

Optional, if you decide to route the native VLAN on a subinterface, Cisco’s inter-VLAN document uses the native keyword, for example encapsulation dot1Q 1 native. This lab does not put a gateway on VLAN 1, so you can leave that out.

Verify:

R1# show ip interface brief
R1# show ip route
R1# show interfaces GigabitEthernet0/0.10

GigabitEthernet0/0, .10, and .20 should be up/up. The routing table should list 192.168.10.0/24 and 192.168.20.0/24 as directly connected. The subinterface status line should mention 802.1Q and the VLAN ID.

For network engineers: these connected routes are enough for two VLANs on one router. No routing protocol is required. If you later add another router, you must advertise or redistribute these networks. Do not put an IP on the parent interface and on a tagged subinterface for the same VLAN. On a live switch, a Layer 3 SVI (interface Vlan10) is the usual alternative to router-on-a-stick.

Address the PCs and set default gateways

The PC’s default gateway must be the router subinterface in that PC’s VLAN, not the other VLAN’s gateway, and not the switch (the switch is Layer 2 here).

Open the VPCS console for PC1:

ip 192.168.10.10/24 192.168.10.1

And on PC2:

ip 192.168.20.20/24 192.168.20.1

If your VPCS build prefers the older form, ip 192.168.10.10 192.168.10.1 24 is the same idea. Use show ip in VPCS to confirm the address, mask, and gateway.

Save the Cisco configs when you are happy with them:

SW1# write memory
R1# write memory

(Or copy running-config startup-config.) VPCS addresses are in the GNS3 project; they are not IOS configs.

Test inter-VLAN routing

From PC1:

  1. Ping its own gateway: ping 192.168.10.1. This must work first. If it fails, stay on VLAN 10 (access VLAN, PC address, no shutdown, router subinterface) and do not debug VLAN 20 yet.
  2. Ping the other gateway: ping 192.168.20.1. This is the first packet that has to be tagged, routed, and tagged again. A failure here, after step 1 works, usually means the trunk, the encapsulation, or the VLAN 20 subinterface.
  3. Ping PC2: ping 192.168.20.20. Both directions should work. Try the same three pings from PC2, starting with 192.168.20.1.

On the router, show arp (or show ip arp) should show both PC addresses and the subinterface each one arrived on. On the switch, show mac address-table should show PC1’s MAC on the VLAN 10 access port and PC2’s MAC on the VLAN 20 port.

A packet from PC1 to PC2: untagged on VLAN 10, tagged on the trunk, routed on the router, tagged for VLAN 20, then untagged to PC2.

Common mistakes

The physical router interface is still shut. Subinterfaces are down, pings to both gateways fail, and show ip interface brief shows the parent administratively down. Add no shutdown on GigabitEthernet0/0. This is easy to miss because you never typed an IP on that interface.

Missing encapsulation dot1Q. The subinterface may take an IP address and still not tag or accept tagged frames. show interfaces GigabitEthernet0/0.10 should mention 802.1Q and VLAN 10.

Native VLAN mismatch. On an 802.1Q trunk, one VLAN is untagged (the native VLAN). It must be the same on the switch and the router. Cisco’s inter-VLAN routing document calls this out as a common mistake. If the switch native VLAN is 1 (typical) and a router subinterface tags VLAN 1 without the native keyword — or the switch native VLAN was changed on one side only — untagged control or data traffic lands in the wrong VLAN. In this lab, leave native VLAN 1 unused and matched, or configure encapsulation dot1Q 1 native if you intentionally put a subnet on it.

The switch port toward the router is still an access port. Only one VLAN will reach the router. show interfaces trunk will not list the port. Set switchport mode trunk (and encapsulation first, if the image requires it).

Access ports in the wrong VLAN, or still in VLAN 1. PC1 can ping nothing useful, or both PCs end up in the same VLAN and “inter-VLAN” appears to work for the wrong reason. Re-check show vlan brief.

Wrong gateway on the PC. A host in VLAN 10 with a gateway of 192.168.20.1 cannot reach that gateway on its local segment. Same-subnet pings to the correct gateway fail, and everything else fails with them.

Subnet or mask typo. .10.1 in VLAN 20, a /25 on one side and a /24 on the other, or a PC address not in its VLAN’s subnet, all break ARP. Read show ip interface brief and show ip on the PCs together.

Allowed VLAN list is too tight. switchport trunk allowed vlan 10 without 20 is enough to break half the lab. Remember that this command replaces the list, it does not add to it, unless you use the add keyword.

Devices not started, or cables on the wrong ports. In GNS3 a stopped node looks like a down link. Confirm the link dots are up and the ports in the lab plan match the ports you configured.

Unexpected interface names. An IOSv port might be GigabitEthernet0/0; a Dynamips image might be FastEthernet0/0; some images start at GigabitEthernet0/0/0. If a command says the interface does not exist, run show ip interface brief and use the name the box actually has.

How this compares to a real closet

On a real small-office switch, the same access-and-trunk idea applies; see Install a network switch. Many offices now route on the firewall or on a Layer 3 switch instead of a dedicated router-on-a-stick. The tags and the gateways still have to match. A controller product such as UniFi or Meraki hides some of the CLI, but a guest SSID is still a VLAN with a gateway — that’s covered in UniFi training and Cisco Meraki Training.

Final checklist

  • GNS3 is using images you are licensed to run, and IOSv / IOSvL2 nodes are hosted on the GNS3 VM if that is what official GNS3 guidance requires for those appliances.
  • The topology is one router, one L2 switch, two PCs, with the trunk and access links on the ports you documented.
  • VLANs 10 and 20 exist; PC ports are access ports in the right VLAN; show vlan brief matches the plan.
  • The switch port to the router is a trunk (encapsulation set if the image requires it), VLANs 10 and 20 are allowed, and the native VLAN matches both ends.
  • Router parent interface has no shutdown. Each subinterface has encapsulation dot1Q for the correct VLAN and the gateway IP for that subnet.
  • show ip route shows both subnets as connected.
  • Each PC has an address in its VLAN and the matching gateway.
  • PC1 pings 192.168.10.1, then 192.168.20.1, then PC2, and the same path works in the other direction.
  • Running configs are saved.

Still stuck?

If the same-VLAN gateway ping works but the other subnet fails, message me with the output of show vlan brief, show interfaces trunk, show ip interface brief, and show ip route (you can paste them as text; no need for a project file). Chat with Technical Terrence

Last updated: November 23, 2026

Sources checked

IEEE 802.1Q is the tagging standard used here. This draft does not quote clause-level IEEE text. ISL is a legacy Cisco trunk type and is not used in the lab.

Not fully verified

  • Exact GNS3 menu labels (“Import appliance”, start button, link tool) can shift between GNS3 versions. The official docs and marketplace are the authority for the installer you have.
  • Interface names and the encapsulation command depend on the IOS image. The body calls that out rather than claiming one name for every template.
  • VPCS ip syntax. Both ip 192.168.10.10/24 192.168.10.1 and ip 192.168.10.10 192.168.10.1 24 are in common VPCS use. If one form is rejected, try the other and confirm with show ip.
  • Subinterface no shutdown. Cisco Press and Cisco’s inter-VLAN document emphasize no shutdown on the physical interface. Some platforms also let you shut a subinterface independently. This lab treats the parent no shutdown as the required step.
  • Built-in GNS3 Ethernet switch. It can trunk, but the UI and VLAN settings are not IOS. I did not treat it as a substitute for the CLI walkthrough.
  • CML / VIRL image terms. Cisco’s current lab-image product names have changed over time. This guide only says to use an image you are licensed to use, and does not document a particular Cisco license SKU.

Related tools