To understand Virtual LAN (VLAN) concepts, configure VLANs on switches, and implement inter-VLAN routing using router-on-a-stick configuration.
In a normal traditional LAN (Local Area Network), all computers are connected through hubs or repeaters. These devices create:
This means any broadcast message sent by one computer is received by every device in the network, and collisions can easily spread through the whole network.
A Virtual Local Area Network (VLAN) is a logical grouping of computers into separate broadcast domains — not based on physical location, but on configuration.
This means:
Broadcast domains become smaller → less unnecessary traffic → faster network
Only devices in the same VLAN can communicate without a router. Sensitive departments (e.g., HR or Finance) can be isolated.
When a user moves desks, you don't need to rewire anything — just change VLAN membership in software.
Users of the same function (e.g., Sales, Marketing) can belong to the same VLAN even if they are physically apart.
Devices in the same VLAN can communicate normally even if they are connected to different switches. Switches use trunk links between them and tag frames so VLAN identity is preserved.
Devices in different VLANs cannot communicate without a router. A router is needed for:
This routing is called Inter-VLAN Routing.
! Step 1 — Enter privileged mode
Switch> enable
! Step 2 — Enter global configuration
Switch# config terminal
! Step 3 — Create VLAN
Switch(config)# vlan 10
Switch(config-vlan)# name Sales
! Step 4 — Assign VLAN to a port (Access Port)
Switch(config)# interface fa0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
! Step 5 — Configure Trunk Port
Switch(config)# interface fa0/24
Switch(config-if)# switchport mode trunk
To allow VLANs to talk to each other, we use a router. We create sub-interfaces on the router:
Example: Router physical port: fa0/0 divided as:
Each sub-interface gets an IP address (as gateway) and encapsulation (dot1q VLAN number)
! Enter router interface
Router(config)# interface fa0/0
! Create sub-interface for VLAN 10
Router(config)# interface fa0/0.10
Router(config-subif)# encapsulation dot1q 10
Router(config-subif)# ip address 192.168.10.1 255.255.255.0
! Create sub-interface for VLAN 20
Router(config)# interface fa0/0.20
Router(config-subif)# encapsulation dot1q 20
Router(config-subif)# ip address 192.168.20.1 255.255.255.0
Components:
vlan 10
name Dept10
vlan 20
name Dept20
! Fa0/1 and Fa0/2 → VLAN 10
interface range fa0/1 - 2
switchport mode access
switchport access vlan 10
! Fa0/3 and Fa0/4 → VLAN 20
interface range fa0/3 - 4
switchport mode access
switchport access vlan 20
! Fa0/5 → Trunk
interface fa0/5
switchport mode trunk
| PC | VLAN | IP Address | Gateway |
|---|---|---|---|
| PC0 | 10 | 192.168.10.2 | 192.168.10.1 |
| PC1 | 10 | 192.168.10.3 | 192.168.10.1 |
| PC2 | 20 | 192.168.20.2 | 192.168.20.1 |
| PC3 | 20 | 192.168.20.3 | 192.168.20.1 |
! Sub-interface for VLAN 10
interface fa0/0.10
encapsulation dot1q 10
ip address 192.168.10.1 255.255.255.0
! Sub-interface for VLAN 20
interface fa0/0.20
encapsulation dot1q 20
ip address 192.168.20.1 255.255.255.0
Ping from: PC1 (VLAN 10) → PC3 (VLAN 20)
Result: Now successful, because router is routing between VLANs