ITNuvoAkademiya
Academy homePackagesPlaylistsToolsSubnet calculatorSearchGlossary
CiscoCCNA · CCNA: networking fundamentals1. Introduction2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise networks · coming soon
LinuxLinux: system administrator üçün · Linux for system administrators1. Getting to know Linux2. Working with text3. Users and permissions4. Processes and packages5. Inside the system6. Monitoring and logs7. NetworkingRed Hat Enterprise Linux · Red Hat Enterprise Linux: from beginner to advanced1. Getting started2. Packages3. Users and permissions4. SELinux5. Services6. Storage7. Networking8. Building services9. Boot and recovery10. DevOps11. Security and monitoring
FortinetFortiGate Administrator · FortiGate Administrator: from first login to ZTNA1. Getting to know FortiGate2. Routing, policy and NAT3. Security profiles4. Users and logs5. Resilience, SD-WAN and automation6. VDOM7. VPN and ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: from installation to alerts1. Introduction2. Installation and the database3. Basics: groups, templates, users4. Connecting devices5. Alerts, Grafana and the API
VirtualizationProxmox VE · coming soonVMware ESXi · coming soon
My account / Sign in
AZENRU
← itnuvo.com

Router on a stick: inter-VLAN routing with sub-interfaces

Lesson 4.26 minIntermediateNovember 4, 2026
Open

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.

R1Fa0/0trunk (802.1Q)SwitchVLAN 10VLAN 20192.168.10.1 /24192.168.20.1 /24
Figure 1 · There is a single cable between the router and the switch. The router needs both VLANs, so this link is a trunk

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:

Physical interface: FastEthernet 0/0Fa0/0.10 (sub-interface)encapsulation dot1Q 10ip 192.168.10.254 /24Fa0/0.20 (sub-interface)encapsulation dot1Q 20ip 192.168.20.254 /24A sub-interface is a virtual interface: each one has its own IP address
Figure 2 · One physical interface, two sub-interfaces: one per VLAN. 192.168.10.254 and 192.168.20.254 are the VLANs' default gateways

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

text
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-interfaceCommandIP address (gateway)VLAN
Fa0/0.10encapsulation dot1Q 10192.168.10.254 /2410
Fa0/0.20encapsulation dot1Q 20192.168.20.254 /2420

Note: the prompt becomes (config-subif): this is sub-interface configuration mode.

The routing table

text
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?

The router has to reach both VLANs over one cable, so the link is a trunk.

2What does the encapsulation dot1Q 20 command do?

The router doesn't know on its own which VLAN belongs to which sub-interface; encapsulation dot1Q tells it.

3What is the default gateway for a computer in VLAN 10?

The VLAN 10 sub-interface (Fa0/0.10) holds 192.168.10.254 and is the gateway for VLAN 10.

4What is a sub-interface?

A sub-interface is a virtual interface. One physical interface can have several sub-interfaces.

5After the configuration, how does 192.168.20.0/24 appear in show ip route?

The sub-interface's network enters the routing table as a directly connected network.
Was this lesson useful?

Comments

Sign in to comment.