Course contents

Chapter 4: VLANs and TrunksLesson 5 of 14

Routing between VLANs

The trunk carries VLANs 10 and 20, but a host in VLAN 10 still cannot reach a host in VLAN 20. What is missing? Let's add a gateway for each subnet and follow the packet through two alternative routing designs.

Intermediate · 5 min read

Why does a working trunk not connect the two subnets?

A VLAN is a Layer 2 Ethernet forwarding group. A subnet is an IP address range. Here we assign one /24 subnet to each VLAN. The switch keeps their local frames separate, including broadcasts. An 802.1Q trunk extends those groups over one cable; it does not turn one group into the other.

A Layer 2 switch does not route traffic from VLAN 10 into VLAN 20. A Layer 3 device (router, firewall or multilayer switch) has to route between the subnets, and each VLAN gets its own gateway address.

The default gateway is the local router address the host uses when no more specific route matches. The employee is 192.168.10.25/24, gateway 192.168.10.1. The other host is 192.168.20.50/24, gateway 192.168.20.1. The goal is a permitted test from the employee to that host, not unrestricted guest access to employee systems.

The source host sends its Ethernet frame to its gateway's MAC address, while the IP packet stays addressed to the destination host. Routing creates a new outgoing frame in the destination VLAN; it does not simply relabel the incoming frame and flood it everywhere.

Design 1: router-on-a-stick

Situation: employee 192.168.10.25 sends to guest device 192.168.20.50. One router link is a trunk, with a subinterface (and gateway) per VLAN.

Router-on-a-stick means one physical router interface carries the VLANs to and from the switch. A subinterface is a logical interface under that physical port. Gi0/0.10 names a subinterface; the command encapsulation dot1Q 10, not the suffix .10, selects its VLAN. Matching the suffix to the VLAN is a useful naming convention.

Gi0/0Gi1/0/23trunkGi1/0/1Gi1/0/3R1Gi0/0.10 · Gi0/0.20SW1VLAN 10EmployeeIP 192.168.10.25VLAN 20Guest deviceIP 192.168.20.50

Device key: R1 (router) · SW1 (switch) · Employee, Guest device (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.

  • R1: Gi0/0.10 · Gi0/0.20
  • Employee: IP 192.168.10.25
  • Guest device: IP 192.168.20.50
  1. 1. Off-subnet, so use the gateway. 192.168.20.50 isn't in 192.168.10.0/24, so the laptop addresses the frame to its gateway 192.168.10.1.
  2. 2. Up the trunk. SW1 tags the frame VLAN 10; R1 receives it on subinterface Gi0/0.10.
  3. 3. Routed. R1 has 192.168.20.0/24 on Gi0/0.20, so (if policy allows) it sends a new frame back down the trunk, tagged VLAN 20.
  4. 4. Delivered. SW1 removes the tag and delivers it on the guest's access port. The destination IP never changed.
One router uplink carries the request into R1 in VLAN 10 and back to SW1 in VLAN 20. A return packet needs the destination host's gateway too.

Before forwarding, the employee uses ARP (Address Resolution Protocol) to find the VLAN 10 gateway's local MAC address. R1 reads the IP destination and selects its connected VLAN 20 route. It resolves the destination host's MAC in VLAN 20, then sends a new frame. IPv4 TTL (Time to Live) decreases at this router hop; the two IP addresses stay the same in this lab, which uses no NAT.

Router subinterfaces can share the physical interface's MAC address. The essential distinction is the frame's forwarding context and destination MAC, not an assumption that every subinterface must have a different MAC.

Build the switch side first

Use isolated Cisco IOS or IOS XE devices supporting these features. Begin in global configuration mode. In this example SW1 Gi1/0/23 connects R1 Gi0/0, and the two hosts connect to Gi1/0/1 and Gi1/0/3.

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 GigabitEthernet1/0/23 switchport mode trunk switchport trunk native vlan 99 switchport trunk allowed vlan 10,20,99 switchport nonegotiate

SW1, global configuration mode. The router-facing trunk is static and permits the two data VLANs plus matching dedicated native VLAN 99.

Give the router one gateway in each subnet

The parent Gi0/0 must be enabled and physically connected. The gateway addresses belong to the subinterfaces, not to the parent in this design. The .99 native subinterface has no user gateway address: it matches the switch's untagged-native classification and is not a third user subnet.

interface GigabitEthernet0/0 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

One subinterface per VLAN; 'encapsulation dot1Q' ties it to the VLAN tag. The native subinterface matches the switch's native VLAN 99.

Design 2: multilayer switch with SVIs

A multilayer switch supports both Ethernet switching and IP routing. It routes internally using Switch Virtual Interfaces (SVIs), one per VLAN, so the illustrated traffic does not need an external router link. Hardware, licensing and platform forwarding capacity determine what it supports; this is not a claim that every switch can route.

Multilayer switchSVI Vlan10 · Vlan20VLAN 10EmployeeIP 192.168.10.25VLAN 20Guest deviceIP 192.168.20.50

Device key: Employee, Guest device (laptop)

Lines show the example’s network connections. 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.

  • Multilayer switch: SVI Vlan10 · Vlan20
  • Employee: IP 192.168.10.25
  • Guest device: IP 192.168.20.50
  1. 1. To the gateway. The laptop's gateway, 192.168.10.1, is the switch's own SVI for VLAN 10.
  2. 2. Routed inside the switch. The switch routes from SVI Vlan10 to SVI Vlan20 and delivers the frame on the guest's port.
In the alternative design, the switch itself owns the two gateway addresses. The IP routing decision stays inside this multilayer switch.
vlan 10 name EMPLOYEES vlan 20 name GUESTS 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

'ip routing' turns on Layer 3 forwarding. With normal autostate, the VLAN must exist and be active, the SVI must be enabled, and an eligible access or trunk port must be up and forwarding for that VLAN. Hardware and licensing must support routing.

interface Vlan10 selects an SVI, a logical Layer 3 interface for VLAN 10. It is not an access port and does not move a host into VLAN 10. Retain the VLAN 10 and 20 access-port membership shown above when using this alternative design. The R1 uplink is not required for routing between these locally attached hosts.

Verify the gateway, route and host separately

For router-on-a-stick, use show ip interface brief to check Gi0/0 and its subinterfaces, and show interfaces trunk on SW1 to check that VLANs 10 and 20 are allowed, active and forwarding. For the SVI design, check Vlan10 and Vlan20 are up/up and ip routing is enabled.

Illustrative Cisco IOS output, shortened and written for this lesson
R1#show ip route connected
C    192.168.10.0/24 is directly connected, GigabitEthernet0/0.10
L    192.168.10.1/32 is directly connected, GigabitEthernet0/0.10
C    192.168.20.0/24 is directly connected, GigabitEthernet0/0.20
L    192.168.20.1/32 is directly connected, GigabitEthernet0/0.20
C marks each directly connected subnet. L marks the router's own local address. No static route between these two connected networks is needed. Equivalent SVI routes would name Vlan10 and Vlan20. A route entry does not prove that a host has the correct return gateway or permits the test traffic.

Short lab: break one forwarding requirement

  1. Choose one design and establish the healthy baseline. Each host should first reach its own gateway. Then test the permitted inter-VLAN path. Use the numeric IPs so a name-resolution failure does not confuse the routing test.
  2. For router-on-a-stick, remove VLAN 20 only from the isolated SW1 uplink using switchport trunk allowed vlan remove 20. The router parent can stay up while VLAN 20 data cannot cross. Compare the trunk list with the router's interface status; up/up alone does not test each VLAN.
  3. Restore the intended list using switchport trunk allowed vlan add 20 on that uplink. The add form retains VLANs 10 and 99. Verify the forwarding list and repeat both gateway and host tests.
  4. If you chose the SVI design instead, deliberately shut only Vlan20 in the isolated lab. Observe its interface state and connected route. Recover with no shutdown under interface Vlan20, confirm normal autostate requirements, and retest. Do not apply both alternative faults at once.

Router-on-a-stick makes a small lab easy to understand, but its VLANs share an uplink and router forwarding capacity. An SVI design avoids that external hop for local routing, while adding a need for routing-capable switch hardware and deliberate policy. Neither design automatically enforces an employee/guest boundary once routes exist.

For the complete switch-port configuration and verification, use the inter-VLAN routing lab.

Either way, VLANs separate traffic but routing reconnects it: use access-control lists (ACLs) or firewall rules to decide what's allowed between them.

Cisco reference

Cisco: inter-VLAN routing using an external router. Configuration assumes IPv4 routing on a supported platform with no NAT or blocking lab policy. Outputs are documentation-based examples, not measurements from physical devices.

Cisco: interface characteristics and SVI autostate

Check the routing decision

Predict · scenario 1

The employee 192.168.10.25/24 sends to 192.168.20.50. Which destination MAC does its first data frame use?

Predict · scenario 2

R1 Gi0/0.10 is configured with encapsulation dot1Q 20. Which value actually selects the VLAN?

Predict · scenario 3

Vlan20 has an IP and no shutdown, but remains down on a multilayer switch. What is still required under normal autostate?