Sub topic 10
Routing Between VLANs
This chapter assumes you know Ethernet frames and MAC addresses, how a switch learns and forwards frames, IPv4 subnets, and basic switch and router command-line use. It also assumes you have met access ports, trunk ports and the 802.1Q tag.
Why VLANs cannot talk on their own
Each VLAN is a separate Layer 2 broadcast domain, and each VLAN normally maps to its own IP subnet. A host in VLAN 10 that wants to reach a host in VLAN 20 sees a destination in a different subnet. It therefore sends the frame to its default gateway. Only a Layer 3 device can forward packets between subnets, so traffic between VLANs always needs a router or a Layer 3 switch.
Router-on-a-stick
In router-on-a-stick, one physical router interface connects to a switch trunk. The router splits that interface into subinterfaces, one per VLAN. Each subinterface reads and writes frames tagged with one VLAN ID and holds the default gateway address for that VLAN's subnet.
The router configuration:
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.0The physical interface carries no IP address. The encapsulation dot1Q 10 line tells the subinterface to match frames tagged with VLAN 10 and to tag its own outgoing frames with VLAN 10. The switch port facing the router must be a trunk that allows VLANs 10 and 20.
Following one packet
Host A (192.168.10.5) pings Host B (192.168.20.5).
- Host A sees that 192.168.20.5 is off-subnet. It ARPs for its gateway, 192.168.10.1, and sends the frame to the router's MAC address.
- The switch forwards the frame out the trunk with a VLAN 10 tag.
- The router receives it on
Gi0/0.10, removes the Ethernet header, and looks up 192.168.20.0/24 in its routing table. That network is connected onGi0/0.20. - The router builds a new frame with a VLAN 20 tag and sends it out the same physical interface.
- The switch delivers the frame to Host B's access port, removing the tag.
Both directions share one link, so the trunk's bandwidth limits inter-VLAN throughput. That limit is the main drawback of this design.
Switched virtual interfaces
A Layer 3 switch routes in hardware between VLANs without leaving the device. You create a switched virtual interface (SVI) for each VLAN. Each SVI holds the gateway address for its VLAN.
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 shutdownAn SVI comes up only if the VLAN exists on the switch and at least one port in that VLAN is up. The ip routing command is required. Without it, the switch behaves as a Layer 2 device.
| Feature | Router-on-a-stick | Layer 3 switch (SVI) |
|---|---|---|
| Forwarding | Router CPU or router hardware | Switch hardware |
| Bottleneck | Single trunk link | Switch backplane |
| Typical use | Small sites, labs | Campus and data center |
Common errors
- A host has the wrong default gateway, or none. Check that it matches the subinterface or SVI address.
- The trunk to the router does not allow one of the VLANs. Use
show interfaces trunk. - The
encapsulation dot1Qnumber does not match the VLAN ID. - The VLAN is missing from the switch, so the SVI stays down.
ip routingis missing on a Layer 3 switch.
Exercise
A router-on-a-stick has subinterface Gi0/0.30 with encapsulation dot1Q 30, but hosts in VLAN 30 cannot reach their gateway. Other VLANs work. Name two things you would check on the switch.
Show answer
Check that VLAN 30 exists on the switch (show vlan brief) and that the trunk toward the router allows VLAN 30 (show interfaces trunk). Also confirm the hosts' access ports are assigned to VLAN 30.