Router on a stick: inter-VLAN routing with sub-interfaces
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- Traffic between different VLANs needs a router. Router on a stick: one cable between router and switch, and that link is a trunk.
- You create sub-interfaces on the router's physical interface: virtual interfaces, each with its own IP address. Any number works; using the VLAN number is convenient (Fa0/0.10, Fa0/0.20).
encapsulation dot1Q <vlan>is essential: the router has no way of knowing on its own which VLAN belongs to which sub-interface.- A sub-interface's IP address is that VLAN's default gateway: 192.168.10.254 for VLAN 10, 192.168.20.254 for VLAN 20.
- On the physical interface you only do no shutdown. The sub-interfaces appear in the routing table as connected (C), and the router routes between the VLANs.
How do VLANs talk to each other?
When we covered VLANs, we explained how computers in different VLANs can communicate: you can do it with router on a stick. Back then we didn't show the configuration, because we hadn't talked about routers yet. Now you know how a router works, so let's look at the configuration.
The switch has VLAN 10 and VLAN 20, and there is only a single cable between the router and the switch. The router needs access to both VLANs, so the link between the router and the switch will be a trunk.
Sub-interfaces
You can create sub-interfaces on a router. These are virtual interfaces, and you can configure an IP address on each one:
You can pick any number you like for a sub-interface. Here the VLAN numbers were chosen: one sub-interface for VLAN 10 and another for VLAN 20.
Configuration
R1(config)#interface fastEthernet 0/0 R1(config-if)#no shutdown R1(config-if)#exit R1(config)#interface fastEthernet 0/0.10 R1(config-subif)#encapsulation dot1Q 10 R1(config-subif)#ip address 192.168.10.254 255.255.255.0 R1(config-subif)#exit R1(config)#interface fastEthernet 0/0.20 R1(config-subif)#encapsulation dot1Q 20 R1(config-subif)#ip address 192.168.20.254 255.255.255.0
Here you see the two sub-interfaces and their IP addresses:
- 192.168.10.254: the default gateway for computers in VLAN 10.
- 192.168.20.254: the default gateway for computers in VLAN 20.
One important command is encapsulation dot1Q. The router has no way of knowing on its own which VLAN belongs to which sub-interface, so we have to use this command. Fa0/0.10 will belong to VLAN 10 and Fa0/0.20 to VLAN 20.
| Sub-interface | Command | IP address (gateway) | VLAN |
|---|---|---|---|
| Fa0/0.10 | encapsulation dot1Q 10 | 192.168.10.254 /24 | 10 |
| Fa0/0.20 | encapsulation dot1Q 20 | 192.168.20.254 /24 | 20 |
Note: the prompt becomes (config-subif): this is sub-interface configuration mode.
The routing table
R1#show ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP ... Gateway of last resort is not set C 192.168.10.0/24 is directly connected, FastEthernet0/0.10 C 192.168.20.0/24 is directly connected, FastEthernet0/0.20
Both sub-interfaces are in the routing table. This lets the router route between the two VLANs.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1In router on a stick, which mode must the link between the router and the switch be in?
2What does the encapsulation dot1Q 20 command do?
3What is the default gateway for a computer in VLAN 10?
4What is a sub-interface?
5After the configuration, how does 192.168.20.0/24 appear in show ip route?
Comments
Sign in to comment.