802.1Q Subinterfaces on IOS XE Routers
Black Belt: Advanced Routing
Route traffic between VLANs using subinterfaces on a single physical link. This "router-on-a-stick" design lets one router interface serve multiple VLANs without needing separate physical connections.
What Is a Subinterface?
A subinterface is a logical subdivision of a physical interface. On a router, each subinterface can have its own IP address and VLAN assignment. By receiving 802.1Q-tagged frames on one trunk link, the router can route traffic between different VLANs without needing multiple physical connections.
Subinterface naming: GigabitEthernet0/0/0.10 means physical interface GigabitEthernet0/0/0, subinterface .10 (often the VLAN number for clarity).
Router-on-a-Stick: The Design
A router connected to a switch via one trunk link can route between all VLANs on that switch:
- The switch tags frames with the VLAN ID and sends them across the trunk to the router.
- The router receives tagged frames on one physical interface, de-tags them on the appropriate subinterface, and routes based on the destination IP.
- The router re-tags the outbound frame with the destination VLAN and sends it back to the switch.
This is a classic design for small to medium networks. For high-traffic scenarios or many VLANs, consider a Layer 3 switch (switch with built-in routing) instead.
Configuration: Step by Step
This example configures a Cisco IOS XE router to route between VLAN 10 (Engineering) and VLAN 20 (Sales) using subinterfaces on one trunk link.
Step 1: Prepare the Physical Interface
Router> enable
Router# configure terminal
Router(config)# interface GigabitEthernet0/0/0
Router(config-if)# no ip address
Router(config-if)# no shutdown
Router(config-if)# exit
Explanation: The physical interface carries 802.1Q-tagged frames, so it has no IP address itself. no shutdown brings it up so it can pass traffic to subinterfaces.
Step 2: Create Subinterface for VLAN 10
Router(config)# interface GigabitEthernet0/0/0.10
Router(config-subif)# encapsulation dot1Q 10
Router(config-subif)# ip address 192.168.10.1 255.255.255.0
Router(config-subif)# description VLAN 10 - Engineering
Router(config-subif)# no shutdown
Router(config-subif)# exit
Explanation: encapsulation dot1Q 10 tells the router to expect and handle frames tagged with VLAN 10 on this subinterface. The IP 192.168.10.1 becomes the gateway for VLAN 10 on the switch.
Step 3: Create Subinterface for VLAN 20
Router(config)# interface GigabitEthernet0/0/0.20
Router(config-subif)# encapsulation dot1Q 20
Router(config-subif)# ip address 192.168.20.1 255.255.255.0
Router(config-subif)# description VLAN 20 - Sales
Router(config-subif)# no shutdown
Router(config-subif)# exit
Step 4: Save Configuration
Router(config)# end
Router# write memory
Building configuration...
[OK]
Switch Configuration (the Other End)
The switch port connected to the router must be a trunk and allow the VLANs:
Switch# configure terminal
Switch(config)# interface GigabitEthernet1/0/24
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk allowed vlan 10,20
Switch(config-if)# switchport trunk native vlan 1
Switch(config-if)# description Trunk to Router
Switch(config-if)# no shutdown
Switch(config-if)# exit
Switch(config)# end
Switch# write memory
Explanation: switchport mode trunk makes it a trunk; switchport trunk allowed vlan 10,20 allows traffic from both VLANs across this link.
Configuration with a Routed Port-Channel
If the link to the router is an EtherChannel for redundancy, use a routed port-channel instead of a single physical interface:
Router# configure terminal
Router(config)# interface Port-channel1
Router(config-if)# no ip address
Router(config-if)# no shutdown
Router(config-if)# exit
Router(config)# interface GigabitEthernet0/0/0
Router(config-if)# no ip address
Router(config-if)# channel-group 1 mode active
Router(config-if)# no shutdown
Router(config-if)# exit
Router(config)# interface GigabitEthernet0/0/1
Router(config-if)# no ip address
Router(config-if)# channel-group 1 mode active
Router(config-if)# no shutdown
Router(config-if)# exit
Router(config)# interface Port-channel1.10
Router(config-subif)# encapsulation dot1Q 10
Router(config-subif)# ip address 192.168.10.1 255.255.255.0
Router(config-subif)# no shutdown
Router(config-subif)# exit
Router(config)# interface Port-channel1.20
Router(config-subif)# encapsulation dot1Q 20
Router(config-subif)# ip address 192.168.20.1 255.255.255.0
Router(config-subif)# no shutdown
Router(config-subif)# end
Router# write memory
Explanation: Create a port-channel, add physical interfaces to it with channel-group, then create subinterfaces on the port-channel itself. This provides redundancy: if one physical link fails, the other carries all VLAN traffic.
Verify Configuration
Check that subinterfaces exist and have IP addresses:
Router# show ip interface brief
Interface IP-Address Status Protocol
GigabitEthernet0/0/0 unassigned up up
GigabitEthernet0/0/0.10 192.168.10.1 up up
GigabitEthernet0/0/0.20 192.168.20.1 up up
Show details of one subinterface:
Router# show interfaces GigabitEthernet0/0/0.10
GigabitEthernet0/0/0.10 is up, line protocol is up
Hardware is Gigabit Ethernet, address is aabb.cc00.0001
Internet address is 192.168.10.1, mask 255.255.255.0
MTU 1500 bytes, BW 1000000 Kbit/sec
Encapsulation 802.1Q Virtual LAN, VLAN ID 10
Verify the routing table can reach both subnets:
Router# show ip route
Codes: C - connected, S - static, R - RIP, B - BGP
O - OSPF, IA - OSPF inter area
Gateway of last resort is not set
C 192.168.10.0/24 is directly connected, GigabitEthernet0/0/0.10
C 192.168.20.0/24 is directly connected, GigabitEthernet0/0/0.20
Test connectivity from a device in VLAN 10 to a device in VLAN 20 by pinging the VLAN 20 gateway:
VLAN10-PC> ping 192.168.20.1
Pinging 192.168.20.1 with 32 bytes of data:
Reply from 192.168.20.1: bytes=32 time=2ms TTL=255
Reply from 192.168.20.1: bytes=32 time=1ms TTL=255
Reply from 192.168.20.1: bytes=32 time=2ms TTL=255
Common Mistakes
- Forgetting
no shutdownon the physical interface: If the physical interface is shut down, no subinterfaces will work. Always bring it up. - Missing
encapsulation dot1Q: Without this command, the subinterface won't recognize tagged frames for that VLAN. Every subinterface must have an encapsulation statement. - Native VLAN mismatch: If the switch's native VLAN doesn't match the router's expectation, untagged traffic may fail. Set
switchport trunk native vlanon the switch and create a subinterface for it on the router (or omit the subinterface if you don't need to route that VLAN). - Allowed VLANs not matching: If the switch restricts allowed VLANs on the trunk and doesn't include a VLAN the router expects, traffic for that VLAN won't cross the link.
Subinterface Naming Convention
It's a best practice to name the subinterface with the VLAN ID (e.g., GigabitEthernet0/0/0.10 for VLAN 10). This makes the configuration self-documenting and prevents accidental mismatches between the subinterface number and the VLAN ID.
Summary
- Subinterfaces allow one physical link to route traffic between multiple VLANs using 802.1Q tagging.
- Configure the physical interface with
no ip addressandno shutdown, then create subinterfaces withencapsulation dot1Q <vlan>and an IP address for that VLAN's gateway. - The switch port connected to the router must be a trunk and allow all VLANs the router serves.
- For redundancy, use a routed port-channel with LACP and create subinterfaces on the port-channel.
- Verify with
show ip interface briefandshow interfaces <subif>; test with ping andshow ip route.