Home CS Fundamentals VLAN and Network Segmentation: A Developer's Guide to Virtual LANs
Intermediate 3 min · July 13, 2026

VLAN and Network Segmentation: A Developer's Guide to Virtual LANs

Learn VLAN fundamentals, how they segment networks, and real-world debugging.

N
Naren Founder & Principal Engineer

20+ years shipping production systems from the metal up. Lessons pulled from things that broke in production.

Follow
Production
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
Before you start⏱ 15-20 min read
  • Basic understanding of Ethernet and switching
  • Familiarity with IP addressing and subnetting
  • Access to a network simulator (e.g., Packet Tracer) or real switches for practice
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer

VLANs logically segment a physical network into isolated broadcast domains, improving security and performance. They work by tagging Ethernet frames with VLAN IDs (IEEE 802.1Q). Trunk ports carry multiple VLANs, while access ports assign a single VLAN to devices. VLANs reduce broadcast traffic and enforce access control without additional hardware.

✦ Definition~90s read
What is VLAN and Network Segmentation?

A VLAN (Virtual Local Area Network) is a logical segmentation of a physical network into isolated broadcast domains using 802.1Q tagging.

Imagine a large office building with many departments.
Plain-English First

Imagine a large office building with many departments. Without VLANs, it's like everyone sharing one giant room—noise and chaos. VLANs are like putting each department in its own soundproof glass room: they can see each other but only talk within their room. The building's wiring (physical network) is the same, but the rooms (VLANs) keep conversations separate.

In modern networks, performance and security are paramount. As a developer, you might deploy applications across multiple servers, each needing isolation from others. Without proper segmentation, broadcast storms can cripple performance, and a single compromised device can sniff traffic across the entire network. This is where VLANs (Virtual Local Area Networks) come in. VLANs allow you to partition a physical network into multiple logical networks, each acting as its own broadcast domain. This means devices in VLAN 10 cannot directly communicate with devices in VLAN 20 without a router. The magic happens through frame tagging: each Ethernet frame gets a VLAN ID (12-bit field in the IEEE 802.1Q header) that switches use to forward traffic only to ports in the same VLAN. For developers, understanding VLANs is crucial for designing secure multi-tenant architectures, debugging connectivity issues, and optimizing network performance. This guide will walk you through VLAN concepts, configuration, debugging, and real-world pitfalls—all with practical examples you can apply immediately.

What is a VLAN?

A VLAN (Virtual Local Area Network) is a logical grouping of devices on a physical network. Devices in the same VLAN behave as if they are on their own isolated network, even if they share the same switch. VLANs are defined by a 12-bit VLAN ID (1-4094) in the IEEE 802.1Q standard. When a switch receives a frame, it adds a 4-byte tag containing the VLAN ID before forwarding. This tag is removed at the destination access port. VLANs reduce broadcast traffic, improve security by isolating sensitive data, and allow network administrators to group users by function (e.g., developers, HR) without physical rewiring.

vlan_basics.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Show VLAN database on a Cisco switch
show vlan brief

# Example output:
# VLAN Name                             Status    Ports
# ---- -------------------------------- --------- -------------------------------
# 1    default                          active    Fa0/1, Fa0/2, Fa0/3
# 10   Development                      active    Fa0/4, Fa0/5
# 20   Production                       active    Fa0/6, Fa0/7

# Create a VLAN
configure terminal
vlan 30
 name Staging
exit

# Assign port to VLAN
interface fastEthernet 0/8
 switchport mode access
 switchport access vlan 30
end
🔥VLAN IDs
📊 Production Insight
Always use VLAN IDs > 1000 for temporary or testing VLANs to avoid conflicts with default configurations.
🎯 Key Takeaway
VLANs logically segment a network at Layer 2, using 802.1Q tags to identify membership.

Access Ports vs Trunk Ports

Switch ports operate in two modes: access and trunk. An access port belongs to a single VLAN and carries untagged traffic. It is used to connect end devices like servers, desktops, or printers. A trunk port carries traffic for multiple VLANs and uses 802.1Q tagging to distinguish frames. Trunks connect switches to each other or to routers (router-on-a-stick). Understanding the difference is critical: misconfiguring a trunk as an access port can isolate a switch, while misconfiguring an access port as a trunk can cause VLAN hopping.

access_trunk_config.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Configure an access port
interface gigabitEthernet 0/1
 switchport mode access
 switchport access vlan 10
 no shutdown

# Configure a trunk port
interface gigabitEthernet 0/24
 switchport mode trunk
 switchport trunk allowed vlan 10,20,30
 switchport trunk native vlan 999  # unused VLAN for security
 no shutdown

# Verify configuration
show interfaces gigabitEthernet 0/1 switchport
show interfaces trunk
⚠ Native VLAN Security
📊 Production Insight
When connecting two switches, ensure both ends are configured as trunks with the same allowed VLANs and native VLAN. Mismatches cause connectivity issues.
🎯 Key Takeaway
Access ports carry one VLAN untagged; trunk ports carry multiple VLANs tagged. Never leave native VLAN as default.

Inter-VLAN Routing

By default, VLANs are isolated; devices in different VLANs cannot communicate. To enable communication, you need a Layer 3 device (router or Layer 3 switch). The classic method is 'router-on-a-stick': a single router interface is configured as a trunk, and subinterfaces are created for each VLAN with an IP address. The router performs routing between subinterfaces. Modern networks use Layer 3 switches with switched virtual interfaces (SVIs) for better performance.

router_on_a_stick.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Router configuration for inter-VLAN routing
interface gigabitEthernet 0/0
 no shutdown

interface gigabitEthernet 0/0.10
 encapsulation dot1Q 10
 ip address 192.168.10.1 255.255.255.0

interface gigabitEthernet 0/0.20
 encapsulation dot1Q 20
 ip address 192.168.20.1 255.255.255.0

# On Layer 3 switch (SVI)
interface vlan 10
 ip address 192.168.10.254 255.255.255.0
 no shutdown

interface vlan 20
 ip address 192.168.20.254 255.255.255.0
 no shutdown

ip routing  # Enable Layer 3 routing
💡Performance Consideration
📊 Production Insight
Always apply ACLs on SVIs or router subinterfaces to control traffic between VLANs. Default permit all can be a security risk.
🎯 Key Takeaway
Inter-VLAN routing requires a Layer 3 device. Use SVIs on switches for better performance than router-on-a-stick.

VLAN Trunking Protocol (VTP)

VTP is a Cisco proprietary protocol that propagates VLAN information across switches. It simplifies management by allowing you to create VLANs on one switch (server) and have them automatically learned by others (clients). However, VTP can be dangerous: a misconfigured server can delete all VLANs across the network. In production, VTP is often disabled or set to transparent mode to avoid accidents.

vtp_config.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Configure VTP server
configure terminal
vtp mode server
vtp domain TheCodeForge
vtp password securepass

# Configure VTP client
configure terminal
vtp mode client
vtp domain TheCodeForge
vtp password securepass

# Transparent mode (recommended for production)
configure terminal
vtp mode transparent

# Verify VTP status
show vtp status
⚠ VTP Dangers
📊 Production Insight
If you must use VTP, set a VTP password and ensure all switches have the same domain. Monitor revision numbers with 'show vtp status'.
🎯 Key Takeaway
VTP automates VLAN distribution but can cause catastrophic failures. Use transparent mode or manual configuration in production.

VLAN Security Best Practices

VLANs enhance security but are not foolproof. Common attacks include VLAN hopping (where an attacker sends tagged frames to access another VLAN) and double tagging (encapsulating a frame with two 802.1Q headers). Mitigations: disable Dynamic Trunking Protocol (DTP) on access ports, set native VLAN to an unused ID, prune unused VLANs from trunks, and use private VLANs for isolation within a VLAN. Additionally, implement ACLs and port security.

vlan_security.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Disable DTP on access ports
interface range fastEthernet 0/1-24
 switchport mode access
 switchport nonegotiate

# Set native VLAN to unused (e.g., 999)
interface gigabitEthernet 0/1
 switchport trunk native vlan 999

# Prune VLAN 1 from trunk
interface gigabitEthernet 0/1
 switchport trunk allowed vlan remove 1

# Enable port security
interface fastEthernet 0/1
 switchport port-security
 switchport port-security maximum 2
 switchport port-security violation shutdown
 switchport port-security mac-address sticky
🔥Private VLANs
📊 Production Insight
Always test security configurations in a lab. Misconfiguring port security can lock out legitimate devices.
🎯 Key Takeaway
Secure VLANs by disabling DTP, changing native VLAN, pruning unused VLANs, and using port security.

Troubleshooting VLAN Connectivity

When hosts in the same VLAN cannot communicate, start with the basics: check if the VLAN exists on the switch, if ports are in the correct VLAN, and if the switch is learning MAC addresses. Use 'show mac address-table' to see which MACs are learned on which VLAN. For inter-VLAN issues, verify routing tables and ACLs. Tools like ping, traceroute, and Wireshark are invaluable. Common pitfalls: VLAN mismatch between switch and host (if host uses 802.1Q), native VLAN mismatch on trunks, and STP blocking ports.

troubleshoot_vlan.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Check VLAN existence
show vlan id 10

# Check port VLAN assignment
show interfaces fastEthernet 0/1 switchport

# Check MAC address table
show mac address-table vlan 10

# Check trunk status
show interfaces trunk

# Test connectivity from switch
ping 192.168.10.1 source vlan 10

# Capture packets on a port (if supported)
monitor session 1 source interface fastEthernet 0/1
monitor session 1 destination interface fastEthernet 0/24
💡Use CDP/LLDP
📊 Production Insight
In large networks, use a network monitoring tool (e.g., SolarWinds, PRTG) to alert on VLAN changes or port flapping.
🎯 Key Takeaway
Systematic troubleshooting: verify VLAN, port mode, MAC learning, and trunk configuration. Use switch diagnostic commands.
● Production incidentPOST-MORTEMseverity: high

The Broadcast Storm That Took Down a SaaS Platform

Symptom
All servers in the data center became unresponsive; network latency spiked to 5000ms; users saw 'Connection Timed Out' errors.
Assumption
The developer assumed a DDoS attack was underway and initiated DDoS mitigation procedures.
Root cause
A new switch was added with a trunk port configured to allow all VLANs (native VLAN 1) but the port was accidentally set to 'trunk' mode on an access port, causing VLAN 1 broadcasts to loop through the network.
Fix
Disabled the misconfigured trunk port, reconfigured it as an access port in the correct VLAN, and enabled Spanning Tree Protocol (STP) to prevent loops.
Key lesson
  • Always explicitly define allowed VLANs on trunk ports (e.g., 'switchport trunk allowed vlan 10,20').
  • Change the native VLAN from default (VLAN 1) to an unused VLAN to prevent VLAN hopping.
  • Enable STP on all switches to detect and block loops.
  • Monitor broadcast traffic with SNMP or sFlow to catch anomalies early.
  • Document all network changes and have a rollback plan.
Production debug guideSymptom to Action4 entries
Symptom · 01
Hosts in same VLAN cannot ping each other
Fix
Check if switch ports are in the correct VLAN (access vs trunk). Verify VLAN exists on the switch. Check for VLAN mismatch between switch and host (if using 802.1Q tagging).
Symptom · 02
Hosts in different VLANs can communicate unexpectedly
Fix
Check for a router or Layer 3 switch performing inter-VLAN routing. Verify ACLs or firewall rules. Ensure no accidental trunk port bridging VLANs.
Symptom · 03
Broadcast storms causing network slowdown
Fix
Identify the source MAC address of excessive broadcasts. Check for loops (STP disabled). Isolate the offending port and disable it. Review trunk port configurations.
Symptom · 04
VLAN not appearing in 'show vlan' output
Fix
Ensure VLAN is created on the switch (global config). Check if VLAN is in active state. Verify VTP (if used) is not pruning the VLAN.
★ Quick Debug Cheat Sheet for VLANsCommon symptoms and immediate actions for VLAN issues.
Cannot ping across VLAN
Immediate action
Check router-on-a-stick or Layer 3 switch config
Commands
show ip interface brief
show vlan
Fix now
Add VLAN to router subinterface with correct encapsulation
Host gets wrong IP (DHCP)+
Immediate action
Verify DHCP server is in same VLAN or has IP helper
Commands
show ip dhcp binding
debug ip dhcp server events
Fix now
Configure 'ip helper-address' on VLAN interface
Trunk port not passing traffic+
Immediate action
Check trunk encapsulation and allowed VLANs
Commands
show interfaces trunk
show running-config interface <port>
Fix now
Set 'switchport mode trunk' and 'switchport trunk allowed vlan add <vlan-id>'
VLAN hopping suspected+
Immediate action
Disable DTP and set native VLAN to unused
Commands
show interfaces <port> switchport
show vlan
Fix now
Set 'switchport nonegotiate' and 'switchport trunk native vlan <unused>'
FeatureAccess PortTrunk Port
VLANs carriedSingleMultiple
TaggingUntaggedTagged (802.1Q)
Typical connectionEnd device (PC, server)Switch-to-switch, router
Security riskLowHigher (VLAN hopping)
Configurationswitchport mode accessswitchport mode trunk
⚙ Quick Reference
6 commands from this guide
FileCommand / CodePurpose
vlan_basics.shshow vlan briefWhat is a VLAN?
access_trunk_config.shinterface gigabitEthernet 0/1Access Ports vs Trunk Ports
router_on_a_stick.shinterface gigabitEthernet 0/0Inter-VLAN Routing
vtp_config.shconfigure terminalVLAN Trunking Protocol (VTP)
vlan_security.shinterface range fastEthernet 0/1-24VLAN Security Best Practices
troubleshoot_vlan.shshow vlan id 10Troubleshooting VLAN Connectivity

Key takeaways

1
VLANs segment a physical network into logical broadcast domains using 802.1Q tagging.
2
Access ports carry one VLAN; trunk ports carry multiple VLANs with tags.
3
Inter-VLAN routing requires a Layer 3 device (router or Layer 3 switch).
4
Secure VLANs by disabling DTP, changing native VLAN, and pruning unused VLANs.
5
Troubleshoot systematically
check VLAN existence, port mode, MAC table, and trunk config.

Common mistakes to avoid

3 patterns
×

Forgetting to create the VLAN on the switch before assigning ports.

×

Using the default native VLAN (VLAN 1) on trunks.

×

Misconfiguring trunk allowed VLANs, causing some VLANs to be dropped.

INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
Explain how VLAN tagging works using IEEE 802.1Q.
Q02SENIOR
What is VLAN hopping and how do you prevent it?
Q03JUNIOR
Describe the difference between access and trunk ports.
Q01 of 03SENIOR

Explain how VLAN tagging works using IEEE 802.1Q.

ANSWER
802.1Q inserts a 4-byte tag into the Ethernet frame after the source MAC address. The tag contains a 12-bit VLAN ID (0-4095) and a 3-bit priority field. The switch uses this tag to forward the frame only to ports in the same VLAN. The tag is removed before sending to an access port.
FAQ · 4 QUESTIONS

Frequently Asked Questions

01
What is the difference between a VLAN and a subnet?
02
Can a device be in multiple VLANs?
03
What is the maximum number of VLANs on a switch?
04
How do I test VLAN connectivity from a Linux host?
N
Naren Founder & Principal Engineer

20+ years shipping production systems from the metal up. Lessons pulled from things that broke in production.

Follow
Verified
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
🔥

That's Computer Networks. Mark it forged?

3 min read · try the examples if you haven't

Previous
NAT: Network Address Translation Types and Traversal
30 / 30 · Computer Networks
Next
Introduction to DBMS