Course contents

Chapter 4: VLANs and TrunksLesson 6 of 14

Lab: VLANs and router-on-a-stick

Can PC1 reach a colleague on the other floor, then reach a host in a different VLAN? Build the two paths separately so each successful test tells you which part of the network is working.

Intermediate · 18 min read

What are we trying to make work?

PC1 and PC3 are employees in VLAN 10 on different switches. Their frames should cross the inter-switch trunk without passing through a router. PC2 is in VLAN 20, a separate Ethernet group and IP subnet. PC1 needs gateway R1 to reach it. We deliberately permit that routed lab test; a production guest policy may deny it.

A VLAN separates local Ethernet forwarding. A trunk carries multiple VLANs on one link. Router-on-a-stick places several logical router subinterfaces on one physical trunk. Each data subinterface supplies its VLAN's default gateway, the local router address used for remote destinations.

Test the switched path before the routed path. A failure between VLANs is easier to investigate after you have proved the required local links.

Lab equipment and starting state

Build a small two-floor office with router-on-a-stick. Use a router that supports 802.1Q subinterfaces and two switches with 802.1Q trunk support. Interface names vary by model. Start with console access and set the PCs to the static addresses below. Commands and output are documentation-based examples, not lab captures.

The commands use Cisco Catalyst IOS or IOS XE-style Layer 2 switchports and an IOS-style router. Use an isolated emulator, simulator or spare lab devices with the required feature support. Simulator command coverage varies. Begin with the named interfaces free of conflicting configurations, their cables connected and links enabled. Do not erase or repurpose an operational network to reproduce this lab.

Gi0/0Gi1/0/24trunkGi1/0/23Gi1/0/24trunkR1SW1SW2VLAN 10PC1IP 192.168.10.11VLAN 20PC2IP 192.168.20.11VLAN 10PC3IP 192.168.10.12

Device key: R1 (router) · SW1, SW2 (switch) · PC1, PC3 (computer) · PC2 (laptop)

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • PC1: IP 192.168.10.11
  • PC2: IP 192.168.20.11
  • PC3: IP 192.168.10.12
  1. 1. Test 1: same VLAN, two switches. PC1 → PC3 crosses the SW1–SW2 trunk. No router needed.
  2. 2. Test 2: between VLANs. PC1 → PC2 goes up to R1 and back down, tagged VLAN 10 then VLAN 20.
PC1 to PC3 uses the switch-to-switch trunk. PC1 to PC2 instead uses SW1's router-facing trunk in both directions.
DeviceInterfaceVLANIP addressGateway
R1Gi0/0.1010192.168.10.1/24–
R1Gi0/0.2020192.168.20.1/24–
PC1SW1 Gi1/0/110192.168.10.11/24192.168.10.1
PC2SW1 Gi1/0/320192.168.20.11/24192.168.20.1
PC3SW2 Gi1/0/110192.168.10.12/24192.168.10.1
TrunksR1–SW1, SW1–SW210, 20, native 99––

Every /24 host uses mask 255.255.255.0. PC1 and PC3 share network 192.168.10.0/24; PC2 is in 192.168.20.0/24. The VLAN IDs 10 and 20 are switch classifications, not values calculated from those IP addresses. The table pairs one subnet with each VLAN as a design choice.

Create the VLANs, then assign the ports

Reach global configuration mode with configure terminal from the privileged prompt. vlan 10 creates or selects a VLAN; name supplies a label. switchport mode access fixes an endpoint port's role, and switchport access vlan 10 assigns ordinary untagged data to VLAN 10.

SW1 · global configuration mode

vlan 10 name EMPLOYEES vlan 20 name GUESTS vlan 99 name NATIVE interface GigabitEthernet1/0/1 switchport mode access switchport access vlan 10 interface GigabitEthernet1/0/3 switchport mode access switchport access vlan 20 interface range GigabitEthernet1/0/23 - 24 switchport mode trunk switchport trunk allowed vlan 10,20,99 switchport trunk native vlan 99 switchport nonegotiate

SW2 · global configuration mode

vlan 10 name EMPLOYEES vlan 20 name GUESTS vlan 99 name NATIVE interface GigabitEthernet1/0/1 switchport mode access switchport access vlan 10 interface GigabitEthernet1/0/24 switchport mode trunk switchport trunk allowed vlan 10,20,99 switchport trunk native vlan 99 switchport nonegotiate

SW2 uses Gi1/0/24 toward SW1. It has no router-facing trunk in this topology.

Give R1 a gateway for each data VLAN

Use the router-on-a-stick configuration from Design 1 in Routing between VLANs.

interface GigabitEthernet0/0 no ip address no shutdown interface GigabitEthernet0/0.10 encapsulation dot1Q 10 ip address 192.168.10.1 255.255.255.0 interface GigabitEthernet0/0.20 encapsulation dot1Q 20 ip address 192.168.20.1 255.255.255.0 interface GigabitEthernet0/0.99 encapsulation dot1Q 99 native

R1, global configuration mode, on the isolated lab interface. Data gateways belong to .10 and .20; .99 matches the unused untagged-native VLAN and has no host gateway address.

The encapsulation dot1Q value binds a subinterface to a VLAN. The suffix .10 is a helpful name; the encapsulation value is the actual binding. R1 learns both subnets as directly connected when the interfaces are operational, so no static route between VLANs 10 and 20 is needed.

CommandWhat it does
vlan 10 / nameCreates the VLAN in the switch's database and labels it
switchport mode accessFixes the port as access rather than negotiating a trunk; changing the configuration can change the role
switchport access vlan 10Puts the port's device into VLAN 10
switchport mode trunkMakes the port a permanent 802.1Q trunk
switchport trunk allowed vlanLimits the trunk to the VLANs listed
switchport trunk native vlan 99Moves untagged trunk traffic to unused VLAN 99, on both ends

Some older platforms also need switchport trunk encapsulation dot1q before switchport mode trunk.

Learn more: Lab: Inter-VLAN Routing

What the working lab shows

Illustrative Cisco Catalyst IOS XE output, shortened and written for this lesson
SW1#show vlan brief
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Gi1/0/2, Gi1/0/4, Gi1/0/5, ...
10   EMPLOYEES                        active    Gi1/0/1
20   GUESTS                           active    Gi1/0/3
99   NATIVE                           active
1002 fddi-default                     act/unsup
1003 token-ring-default               act/unsup
1004 fddinet-default                  act/unsup
1005 trnet-default                    act/unsup
Each access port is listed beside its VLAN. This output is not the trunk membership list: Gi1/0/23 and Gi1/0/24 are missing on purpose. VLANs 1002–1005 are legacy defaults you can ignore.
Illustrative Cisco Catalyst IOS XE output, shortened and written for this lesson
SW1#show interfaces trunk
Port        Mode             Encapsulation  Status        Native vlan
Gi1/0/23    on               802.1q         trunking      99
Gi1/0/24    on               802.1q         trunking      99

Port        Vlans allowed on trunk
Gi1/0/23    10,20,99
Gi1/0/24    10,20,99

Port        Vlans allowed and active in management domain
Gi1/0/23    10,20,99
Gi1/0/24    10,20,99

Port        Vlans in spanning tree forwarding state and not pruned
Gi1/0/23    10,20,99
Gi1/0/24    10,20,99
Status: trunking means the link is up as a trunk. Native vlan must match the other end. A VLAN must appear in all three lists to actually be forwarded: allowed, active (it exists on this switch), and in spanning-tree forwarding state without pruning. Verify the far end too.
Illustrative Cisco IOS router output, written for this lesson
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.99  unassigned      YES unset  up                    up
The data subinterfaces .10 and .20 should be up/upwith their gateway addresses. The unused native .99 subinterface and physical Gi0/0 have no IP address. Subinterface up/up alone does not prove that the switch trunk carries the VLAN.
show ip route connected

On R1: both 192.168.10.0/24 and 192.168.20.0/24 should appear as connected networks.

Example output from a PC, written for this lesson
PC1> ping 192.168.20.11
Reply from 192.168.20.11: bytes=32 time=1ms TTL=127
Reply from 192.168.20.11: bytes=32 time=1ms TTL=127
A reply from PC2 confirms this ICMP exchange succeeds. If the reply started with TTL 128, TTL=127 is consistent with one routed hop on the return path. TTL alone cannot identify the initial value or prove the complete forwarding path.

A working ping proves connectivity, not that the design is secure. If guests shouldn't reach employees, also test that the prohibited paths are blocked once your ACLs or firewall rules are in place.

ARP (Address Resolution Protocol) finds a local receiver's MAC address. PC1 resolves PC3 directly for the same-subnet test. For PC2, PC1 resolves R1's VLAN 10 gateway instead. The IP destination remains PC2; R1 builds a new frame in VLAN 20. PC2's reply requires its own correct gateway, 192.168.20.1.

Finish and verify

  1. Ping each PC's own gateway, then PC1 → PC3 across the switch trunk, then PC1 → PC2 through R1.
  2. On isolated SW1 Gi1/0/23, use switchport trunk allowed vlan remove 10. Confirm that PC1 → PC3 fails while PC1 → PC2 can still work. The two tests use different SW1 uplinks.
  3. Restore that same interface with switchport trunk allowed vlan add 10. The add form retains VLANs 20 and 99. Verify the trunk lists on both ends, then repeat both tests.
  4. Save only the recovered, intended configuration on R1, SW1 and SW2 with copy running-config startup-config. Do not save the deliberately broken state as the finished lab.

If PC1 cannot reach its own gateway, inspect its address, mask, access port and SW1's router trunk before changing the inter-switch uplink. If PC1 → PC3 works but PC1 → PC2 fails, check R1's connected routes, both host gateways and any host firewall or access-control list (ACL). A missing ping reply alone does not identify the failed device.

Router-on-a-stick saves physical router interfaces, but the data VLANs share the router uplink and forwarding resources. This lab demonstrates the mechanism; it does not measure throughput or prove that the design is suitable for every office.

Explain the results

Predict · scenario 1

PC1 reaches PC3 across the two switches while R1 is disconnected. Why can this work?

Predict · scenario 2

You remove VLAN 10 only from SW1 Gi1/0/23. Which previously working test is expected to fail first?

Predict · scenario 3

Both data subinterfaces on R1 show up/up, but VLAN 20 is missing from SW1's allowed list towards R1. What should you conclude?

Technical references

The switch commands follow Cisco's IOS XE VLAN trunking guide. Router subinterfaces follow its external-router inter-VLAN example. Exact interface names, defaults and output vary by platform. No hardware or simulator execution is claimed.