Understanding VLANs, Trunking and Access Ports
Comprehensive guide to VLANs, 802.1Q trunking, and access port configuration for enterprise switched networks.
# Understanding VLANs, Trunking and Access Ports
Introduction
Virtual Local Area Networks (VLANs) are fundamental to modern switched network design, enabling logical segmentation of a single physical switch infrastructure into multiple broadcast domains. VLANs improve security, reduce broadcast traffic, simplify network management, and provide flexibility in organizing network resources by function rather than physical location.
This tutorial provides a comprehensive technical deep dive into VLANs, 802.1Q trunking, and access port configuration. You will learn VLAN concepts, frame tagging mechanisms, trunk negotiation protocols, VLAN trunking protocol considerations, inter-VLAN routing requirements, and practical configuration for enterprise switching environments.
By the end of this guide, you will be able to design VLAN schemes, configure access and trunk ports, troubleshoot VLAN connectivity issues, and implement secure Layer 2 segmentation.
Technical Background
VLAN Concepts
A VLAN is a logical broadcast domain created on a switch. Devices within the same VLAN can communicate directly at Layer 2, while devices in different VLANs require a Layer 3 device (router or Layer 3 switch) to forward traffic between them.
Key VLAN characteristics:
- **Broadcast isolation**: Broadcast, multicast, and unknown unicast frames are flooded only within the originating VLAN.
- **Logical grouping**: Devices can be grouped by department, function, or security requirement regardless of physical switch location.
- **VLAN IDs**: VLANs are identified by numbers 1–4094. VLAN 1 is the default and cannot be deleted. VLANs 1002–1005 are reserved for FDDI and Token Ring. VLANs 1006–4094 are the extended range.
Frame Tagging and 802.1Q
When frames traverse links between switches carrying multiple VLANs, the switch must identify which VLAN each frame belongs to. The IEEE 802.1Q standard defines frame tagging by inserting a 4-byte tag into the Ethernet frame between the source MAC address and the EtherType field.
802.1Q tag structure:
- **TPID (Tag Protocol Identifier)**: 0x8100, identifies an 802.1Q-tagged frame.
- **PCP (Priority Code Point)**: 3 bits for IEEE 802.1p QoS priority.
- **DEI (Drop Eligible Indicator)**: 1 bit indicating frame may be dropped during congestion.
- **VID (VLAN Identifier)**: 12 bits identifying the VLAN (0 and 4095 reserved).
**Native VLAN**: Untagged frames on an 802.1Q trunk belong to the native VLAN (default VLAN 1). Best practice is to change the native VLAN to an unused VLAN ID and avoid using VLAN 1 for any data traffic.
Access Ports vs. Trunk Ports
**Access ports** belong to a single VLAN and connect to end devices (workstations, printers, servers, access points). The switch removes any 802.1Q tag from ingress frames and forwards untagged frames to end devices. Access ports discard tagged frames unless voice VLAN is configured.
**Trunk ports** carry traffic for multiple VLANs between switches, routers, servers, or access points. Trunk frames are tagged with 802.1Q VLAN identifiers except for the native VLAN, which remains untagged.
Dynamic Trunking Protocol (DTP)
DTP is a Cisco proprietary protocol that negotiates trunking status between switch ports. DTP modes include:
- `access`: Non-trunking port
- `trunk`: Trunking port
- `dynamic auto`: Negotiates trunk if the remote side requests it
- `dynamic desirable`: Actively attempts to negotiate trunking
- `nonegotiate`: Trunking without DTP negotiation
**Security concern**: DTP can be exploited for VLAN hopping attacks. Disable DTP on user-facing ports using `switchport nonegotiate` or configure ports as static access/trunk.
Prerequisites
- Managed Ethernet switches supporting 802.1Q VLANs
- Console or SSH access to switches
- Understanding of Layer 2 switching and broadcast domains
- Network documentation showing VLAN assignments and trunk links
- Maintenance window for production changes
Architecture
VLAN Logical Segmentation
Physical Switch
┌─────────────────────────────────────────────┐
│ │
│ VLAN 10 │ VLAN 20 │ VLAN 30 │ VLAN 40 │
│ (Sales) │ (Engineer)│ (HR) │ (Guest) │
│ │ │ │ │
│ Ports: 1-8│ Ports: 9-16│ Ports:17-24│ Ports:25-32│
│ │ │ │ │
│ Broadcast domain 10 │ Domain 20 │ Domain 30 │ Domain 40│
└─────────────────────────────────────────────┘Trunk Between Switches
Switch A Switch B
┌─────────┐ ┌─────────┐
│ Gi1/0/1 │┌────────────────────────┐│ Gi1/0/1 │
│ Access ││ 802.1Q Trunk ││ Trunk │
│ VLAN 10 ││ VLANs 10,20,30,40 ││ VLANs │
└─────────┘│ Native VLAN: 999 │└─────────┘
└────────────────────────┘graph LR
subgraph Switch_A
A1[Gi1/0/1 - Access VLAN 10]
A2[Gi1/0/2 - Access VLAN 20]
A24[Gi1/0/24 - Trunk 10,20,30]
end
subgraph Switch_B
B1[Gi1/0/1 - Access VLAN 30]
B2[Gi1/0/2 - Access VLAN 40]
B24[Gi1/0/24 - Trunk 10,20,30]
end
A24 <==> 802.1Q ==> B24
A1 --> PC1[(Workstation)]
A2 --> PC2[(Workstation)]
B1 --> SVR[(Server)]
B2 --> AP[(Access Point)]Step-by-Step Implementation
Step 1: Create VLANs on the Switch
**Purpose**: Define VLAN databases before assigning ports.
**Commands** (Cisco IOS):
configure terminal
vlan 10
name Sales
exit
vlan 20
name Engineering
exit
vlan 30
name HR
exit
vlan 40
name Guest
exit
vlan 999
name Unused-Native
exit
end**Configuration files**: Running configuration; save to NVRAM with `copy running-config startup-config`.
**Explanation**: VLANs must exist on the switch before ports can be assigned to them. The `name` parameter is descriptive only and does not affect forwarding.
**Expected output**: VLAN database contains VLANs 10, 20, 30, 40, and 999.
**Verification**:
show vlan briefStep 2: Configure Access Ports
**Purpose**: Assign end-device ports to specific VLANs with security settings.
**Commands**:
configure terminal
interface range GigabitEthernet1/0/1-8
switchport mode access
switchport access vlan 10
switchport port-security
switchport port-security maximum 2
switchport port-security violation restrict
spanning-tree portfast
spanning-tree bpduguard enable
exit
interface range GigabitEthernet1/0/9-16
switchport mode access
switchport access vlan 20
switchport port-security
switchport port-security maximum 2
spanning-tree portfast
spanning-tree bpduguard enable
exit**Configuration files**: Interface-level configuration stored in running-config.
**Explanation**: PortFast skips listening/learning STP states for end-device ports. BPDU guard shuts down the port if a BPDU is received, preventing rogue switches.
**Expected output**: Ports show as access mode in the assigned VLAN; PortFast and BPDU guard active.
**Verification**:
show interfaces switchport
show spanning-tree vlan 10
show port-security interface GigabitEthernet1/0/1Step 3: Configure 802.1Q Trunk Ports
**Purpose**: Carry multiple VLANs between switches with a secure native VLAN.
**Commands**:
configure terminal
interface GigabitEthernet1/0/24
switchport mode trunk
switchport trunk allowed vlan 10,20,30,40
switchport trunk native vlan 999
switchport nonegotiate
spanning-tree portfast trunk
exit**Configuration files**: Trunk interface configuration.
**Explanation**: `switchport trunk allowed vlan` restricts which VLANs traverse the trunk, reducing unnecessary flooded traffic. `switchport nonegotiate` disables DTP. `spanning-tree portfast trunk` accelerates trunk convergence on device-facing trunk ports (e.g., to servers).
**Expected output**: Trunk carries VLANs 10, 20, 30, 40; native VLAN 999 carries untagged traffic.
**Verification**:
show interfaces trunk
show interfaces GigabitEthernet1/0/24 switchport
show spanning-tree vlan 10Step 4: Configure Voice VLAN (Optional)
**Purpose**: Separate IP phone traffic from PC data traffic on the same access port.
**Commands**:
interface GigabitEthernet1/0/5
switchport mode access
switchport access vlan 10
switchport voice vlan 40
switchport port-security maximum 3
spanning-tree portfast**Explanation**: Cisco IP phones support 802.1Q tagging. The phone tags voice traffic with VLAN 40 while PC traffic remains untagged in VLAN 10. The switch forwards both VLANs on a single port.
**Expected output**: Phone receives IP from VLAN 40 DHCP scope; PC receives IP from VLAN 10 scope.
**Verification**:
show interfaces GigabitEthernet1/0/5 switchport
show mac address-table interface GigabitEthernet1/0/5Configuration Examples
Complete Switch Configuration Fragment
!
vlan 10
name Sales
vlan 20
name Engineering
vlan 30
name HR
vlan 40
name Guest
vlan 999
name Unused-Native
!
interface range GigabitEthernet1/0/1-24
description Access-Ports
switchport mode access
switchport access vlan 10
switchport port-security
switchport port-security maximum 2
switchport port-security violation restrict
spanning-tree portfast
spanning-tree bpduguard enable
no shutdown
!
interface GigabitEthernet1/0/24
description Trunk-to-Distribution
switchport mode trunk
switchport trunk allowed vlan 10,20,30,40
switchport trunk native vlan 999
switchport nonegotiate
no shutdown
!
interface range GigabitEthernet1/0/25-48
description VoIP-Ports
switchport mode access
switchport access vlan 10
switchport voice vlan 40
spanning-tree portfast
no shutdownNative VLAN Security Configuration
interface GigabitEthernet1/0/24
switchport mode trunk
switchport trunk native vlan 999
!
vlan 999
name Blackhole-Native
!
interface Vlan999
shutdown**Explanation**: Creating an SVI for the native VLAN and shutting it down prevents Layer 3 connectivity on the native VLAN, reducing VLAN hopping risk.
Verification
CLI Commands
show vlan brief -- List all VLANs and assigned ports
show interfaces switchport -- Show port mode and VLAN assignment
show interfaces trunk -- Show trunk status and allowed VLANs
show mac address-table -- Show MAC-to-port mappings by VLAN
show spanning-tree vlan 10 -- Show STP topology per VLAN
show dtp interface Gi1/0/24 -- Show DTP negotiation status
show port-security address -- Show secured MAC addressesConnectivity Tests
-- From a PC in VLAN 10
ping 10.1.10.10 -- Same VLAN (should succeed)
ping 10.1.20.10 -- Different VLAN (requires Layer 3)
-- From switch
switch# ping 10.1.10.10 -- Verify SVI reachability
switch# traceroute 10.1.20.10 -- Verify inter-VLAN pathExpected Results
- `show vlan brief` lists configured VLANs with correct port assignments
- `show interfaces trunk` displays trunking active with correct allowed VLAN list
- Native VLAN shows as 999, not VLAN 1
- Same-VLAN ping succeeds at Layer 2
- Cross-VLAN ping requires routing (Layer 3 device)
- DTP shows `off` or `nonegotiate` on configured trunk ports
Troubleshooting
| Symptom | Possible Cause | Diagnostic Command | Corrective Action | Verification | |---------|---------------|-------------------|-------------------|--------------| | Device in wrong VLAN | Incorrect access VLAN assignment | `show interfaces switchport` | Change `switchport access vlan` to correct VLAN | Device receives correct subnet | | Trunk not forming | DTP mismatch or `switchport mode access` | `show interfaces trunk` | Set both ends to `switchport mode trunk` | Trunk status shows trunking | | Native VLAN mismatch | Different native VLAN on each end | `show interfaces trunk` | Align native VLAN on both trunk ports | CDP neighbor warnings disappear | | VLAN traffic not crossing trunk | VLAN not in allowed list | `show interfaces trunk` | Add VLAN to `switchport trunk allowed vlan` | Traffic flows for added VLAN | | Excessive broadcasts | Large VLAN without segmentation | `show mac address-table count` | Split VLAN into smaller subnets or add Layer 3 | Broadcast domain reduced | | VLAN hopping via DTP | DTP enabled on user port | `show dtp interface` | Configure `switchport nonegotiate` | DTP disabled | | Port security violation | More MACs than maximum | `show port-security interface` | Increase maximum or remove unauthorized device | No security violations | | STP blocking trunk link | Redundant path creates loop | `show spanning-tree` | Verify intended topology; adjust STP priorities if needed | All uplinks forwarding as designed | | Voice and data on wrong VLANs | Voice VLAN misconfigured | `show interfaces switchport` | Verify `switchport voice vlan` configuration | Phone gets voice VLAN DHCP | | Untagged frames on wrong VLAN | Native VLAN is VLAN 1 | `show interfaces trunk` | Change native VLAN to unused ID | Untagged traffic isolated in VLAN 999 | | Intermittent trunk errors | Duplex/speed mismatch | `show interfaces Gi1/0/24` | Hard-code speed and duplex on both ends | Interface error counters stable |
Best Practices
1. **Never use VLAN 1 for data**: Change the native VLAN to an unused ID and keep VLAN 1 unused or only for switch management. 2. **Prune unused VLANs on trunks**: Only allow VLANs that actually need to traverse each trunk link. 3. **Disable DTP on all ports**: Use static `switchport mode access` or `switchport mode trunk` with `nonegotiate`. 4. **Implement PortFast and BPDU guard**: Apply to all end-device access ports to accelerate convergence and prevent rogue switches. 5. **Document VLAN-to-subnet mapping**: Maintain a spreadsheet or IPAM tool showing each VLAN, subnet, purpose, and gateway. 6. **Use consistent VLAN numbering**: Use the same VLAN IDs across all switches in the network to simplify troubleshooting. 7. **Reserve VLAN ranges**: Allocate VLAN IDs by function (e.g., 1–99 production, 100–199 guest, 900–999 management/unused). 8. **Implement separate management VLAN**: Use an out-of-band or dedicated VLAN for switch management with restricted access. 9. **Limit VLAN scope**: Keep VLANs local to access/distribution pairs; avoid spanning VLANs across the entire network. 10. **Monitor MAC address table**: Watch for CAM table exhaustion and implement port security on access ports.
Conclusion
VLANs, trunking, and access port configuration are foundational skills for enterprise network engineers. Proper VLAN design improves security, reduces broadcast domains, and simplifies network operations. The 802.1Q standard provides interoperable frame tagging across vendors, while access port security features protect against common Layer 2 attacks. Apply these principles consistently across your network infrastructure, and always validate configurations with the verification commands described in this guide.
References
- IEEE 802.1Q-2018 - Bridges and Bridged Networks (https://ieeexplore.ieee.org/)
- Cisco VLAN Configuration Guide (https://www.cisco.com/c/en/us/support/docs/switches/catalyst-6500-series-switches/)
- Juniper VLAN and Bridge Domain Configuration (https://www.juniper.net/documentation/)
- Arista 802.1Q VLAN Configuration (https://www.arista.com/)
- RFC 3069 - VLAN Aggregation for Efficient IP Address Space Allocation
- SANS Institute - Layer 2 Security (https://www.sans.org/)