Inter-VLAN Routing
VLANs can’t talk to each other by default - you need a Layer 3 device (router or multilayer switch) to route between them.
Why Use Inter-VLAN Routing?
Section titled “Why Use Inter-VLAN Routing?”You need inter-VLAN routing when:
- Devices in different VLANs need to communicate (e.g., Sales VLAN needs to access a server in IT VLAN)
- Users need to access resources on other VLANs
- You want VLANs for security but still need controlled connectivity between them
Inter-VLAN Routing Diagram
Section titled “Inter-VLAN Routing Diagram”Without Inter-VLAN Routing:┌─────────────┐ ┌─────────────┐│ VLAN 10 │ │ VLAN 20 ││ PC1 │ XXX │ PC2 │ Can't communicate!│192.168.10.10│ │192.168.20.10│└─────────────┘ └─────────────┘
With Inter-VLAN Routing (Layer 3 Switch/Router):┌─────────────┐ ┌──────────────────┐ ┌─────────────┐│ VLAN 10 │ │ Layer 3 Switch │ │ VLAN 20 ││ PC1 ├──────┤ VLAN 10: .10.1 ├──────┤ PC2 ││192.168.10.10│ │ VLAN 20: .20.1 │ │192.168.20.10││GW: .10.1 │ │ (Routes between)│ │GW: .20.1 │└─────────────┘ └──────────────────┘ └─────────────┘ Traffic routed between VLANs!Method 1: Switch Virtual Interface (SVI)
Section titled “Method 1: Switch Virtual Interface (SVI)”When to use: When you have a multilayer switch (Layer 3 switch). This is the BEST method - fastest and most efficient.
Use on multilayer switches - the switch itself routes between VLANs using hardware.
Requirements:
- Multilayer switch (Layer 3 switch)
- VLAN must exist in VLAN database
- At least one port assigned to the VLAN in up/up state
Configuration:
! Create VLANsSwitch(config)# vlan 10Switch(config-vlan)# name SalesSwitch(config-vlan)# exit
Switch(config)# vlan 20Switch(config-vlan)# name EngineeringSwitch(config-vlan)# exit
! Enable IP routing on the switchSwitch(config)# ip routing
! Create SVIs (one per VLAN)Switch(config)# interface vlan 10Switch(config-if)# ip address 192.168.10.1 255.255.255.0Switch(config-if)# no shutdownSwitch(config-if)# exit
Switch(config)# interface vlan 20Switch(config-if)# ip address 192.168.20.1 255.255.255.0Switch(config-if)# no shutdownParameters:
- 10, 20 - VLAN numbers. Replace with your VLANs.
- Sales, Engineering - VLAN names. Replace with your names (optional).
- 192.168.10.1, 192.168.20.1 - SVI IP addresses (default gateways). Replace with your addressing scheme.
Note:
ip routingenables Layer 3 routing on the switch - this is REQUIRED for SVIs to route between VLANs.
The switch is now the default gateway for devices in VLAN 10 (192.168.10.1) and VLAN 20 (192.168.20.1).
Method 2: Router-on-a-Stick (Subinterfaces)
Section titled “Method 2: Router-on-a-Stick (Subinterfaces)”When to use: When you DON’T have a multilayer switch - only a regular Layer 2 switch and a router. Or when you’re routing VLANs from an external device.
Drawback: Slower than SVIs because all traffic must go through one physical interface to the router.
Use when you only have a router (not a multilayer switch). One physical router interface handles multiple VLANs using subinterfaces.
Configuration:
On the switch (trunk to router):
Switch(config)# interface GigabitEthernet0/1Switch(config-if)# switchport mode trunkSwitch(config-if)# switchport trunk allowed vlan 10,20,30Parameters:
- GigabitEthernet0/1 - Replace with the switch port connected to the router.
- 10,20,30 - VLAN list. Replace with your VLANs.
On the router (subinterfaces with 802.1Q encapsulation):
Router(config)# interface GigabitEthernet0/0Router(config-if)# no shutdownRouter(config-if)# exit
! Subinterface for VLAN 10Router(config)# interface GigabitEthernet0/0.10Router(config-subif)# encapsulation dot1q 10Router(config-subif)# ip address 192.168.10.1 255.255.255.0Router(config-subif)# exit
! Subinterface for VLAN 20Router(config)# interface GigabitEthernet0/0.20Router(config-subif)# encapsulation dot1q 20Router(config-subif)# ip address 192.168.20.1 255.255.255.0Router(config-subif)# exit
! Subinterface for VLAN 30Router(config)# interface GigabitEthernet0/0.30Router(config-subif)# encapsulation dot1q 30Router(config-subif)# ip address 192.168.30.1 255.255.255.0Parameters:
- GigabitEthernet0/0 - Replace with your router’s physical interface connected to the switch.
- GigabitEthernet0/0.10, .20, .30 - Subinterface numbers. Typically match VLAN numbers for clarity.
- 10, 20, 30 - VLAN numbers for dot1q encapsulation. Must match actual VLAN numbers.
- 192.168.10.1, 192.168.20.1, 192.168.30.1 - Default gateway IPs. Replace with your addressing scheme.
Note: The physical interface must be
no shutdownor the subinterfaces won’t work. The number afterdot1qMUST match the VLAN number.
Subinterface numbering: The .10, .20, .30 can be any number, but matching the VLAN ID makes it easier to manage (e.g., subinterface .10 for VLAN 10).
When to Use Which Method
Section titled “When to Use Which Method”| Method | Use Case |
|---|---|
| SVI | Multilayer switch doing inter-VLAN routing (most common, fastest) |
| Router-on-a-stick | Only have a router, or routing VLANs from external switch |
If you have a multilayer switch, always use SVIs - it’s hardware-based routing, much faster than router-on-a-stick.
Verify Configuration
Section titled “Verify Configuration”For SVIs:
Switch# show ip interface briefSwitch# show vlan briefSwitch# show ip routeSwitch# show interfaces vlan 10For Router-on-a-stick:
Router# show ip interface briefRouter# show vlansRouter# show ip routeRouter# show interfaces GigabitEthernet0/0.10Test routing:
Router# ping 192.168.20.1 source 192.168.10.1