Learn / Stage 3: Networking and CCNA / Lesson 3.4

$ lesson 3.4 --track ccna --domain access

VLANs and Trunks: 802.1Q, Native VLAN, DTP, Voice VLAN

VLANs are the first real security boundary inside a network: guests on one side, staff on another, phones in their own lane. Build them, join switches with trunks that cannot be talked into leaking, and understand the two classic VLAN hopping tricks well enough to shut them down.

  • Stage 3 Networking and CCNA
  • Level Intermediate
  • 60 min
  • 5 sections, quiz, lab

Start the lesson Jump to the lab

By the end of this lesson you can

  • Create normal range VLANs and assign data and voice access ports
  • Build 802.1Q trunks with a non default native VLAN and an allowed list
  • Predict the result of each DTP mode pair and switch DTP off
  • Explain switch spoofing and double tagging and apply the standard defences
3.4.01

VLANs: separate networks on shared switches

A VLAN is a separate broadcast domain carved out of shared switches. Ports in VLAN 10 and ports in VLAN 20 behave as if they were on different switches: broadcasts stay inside their VLAN, and traffic between VLANs must go through a router or Layer 3 switch (lesson 3.6), which is exactly where you can filter it.

  • Normal range: 1 to 1005. VLANs 1002 to 1005 are reserved for old FDDI and Token Ring uses. Extended range: 1006 to 4094.
  • VLAN 1 is the default; every port starts there and it cannot be deleted. Good practice is to keep users and management out of it.
  • Each VLAN normally gets its own IP subnet, so your VLSM plan from lesson 3.2 maps straight onto VLANs.
The lab's VLAN plan
VLANNameSubnetPorts on each switch
10STAFF192.168.10.0/24Fa0/1 to Fa0/10
20GUEST192.168.20.0/24Fa0/11 to Fa0/20
30VOICE192.168.30.0/24voice on Fa0/3
99NATIVEno hoststrunk native VLAN only
999PARKINGno hostsFa0/21 to Fa0/24, shut
3.4.02

Access ports and voice VLANs

An access port belongs to one data VLAN and sends untagged frames, so the PC never knows VLANs exist. It can also carry one voice VLAN, so an IP phone and the PC plugged into the phone share one cable: the phone tags its own traffic with the voice VLAN (CDP or LLDP tells it which one), and the PC's traffic stays untagged in the data VLAN.

SW1(config)#vlan 10
SW1(config-vlan)#name STAFF
SW1(config-vlan)#exit
SW1(config)#interface range Fa0/1 - 10
SW1(config-if-range)#switchport mode access
SW1(config-if-range)#switchport access vlan 10
SW1(config-if-range)#switchport nonegotiate
SW1(config-if-range)#interface Fa0/3
SW1(config-if)#switchport voice vlan 30

If you assign a port to a VLAN that does not exist yet, IOS creates it for you with a message such as % Access VLAN does not exist. Creating vlan 10, named VLAN0010. Name your VLANs anyway; names make show vlan brief readable at 2 a.m.

3.4.03

802.1Q trunks, the native VLAN and allowed lists

A trunk carries many VLANs over one link, usually between switches or to a router. It marks each frame's VLAN by inserting a 4 byte 802.1Q tag.

An Ethernet frame with an 802.1Q tag inserted after the source MAC. The tag carries a 12 bit VLAN IDDest MAC6 bytesSrc MAC6 bytes802.1Q tag4 bytesEtherType2 bytesPayload46 to 1500 bytesFCS4 bytesTPID 0x810016 bits: this frame is taggedPCP3 bits: priorityDEI1 bitVLAN ID12 bits: 1 to 4094
The 802.1Q tag sits between the source MAC and the EtherType. Its 12 bit VLAN ID allows VLANs 1 to 4094 (0 and 4095 are reserved).
  • The native VLAN is the one VLAN sent untagged on a trunk (VLAN 1 unless you change it). Both ends must agree. A mismatch makes frames leak between VLANs, and CDP reports it with a message like %CDP-4-NATIVE_VLAN_MISMATCH.
  • The allowed list (switchport trunk allowed vlan 10,20,30,99) limits which VLANs cross the trunk. By default, all of them do.
  • On 2960 class switches only 802.1Q exists, so switchport trunk encapsulation dot1q is not needed (and may be rejected). On 3560 and 3650 class switches you may need it before switchport mode trunk.
SW1(config)#interface GigabitEthernet0/1
SW1(config-if)#switchport mode trunk
SW1(config-if)#switchport trunk native vlan 99
SW1(config-if)#switchport trunk allowed vlan 10,20,30,99
SW1(config-if)#switchport nonegotiate
SW1#show interfaces trunk
3.4.04

DTP: when two switches negotiate a trunk

Cisco switches can negotiate whether a link becomes a trunk using DTP (Dynamic Trunking Protocol). The result depends on the mode at each end:

DTP results
dynamic autodynamic desirabletrunkaccess
dynamic autoaccesstrunktrunkaccess
dynamic desirabletrunktrunktrunkaccess
trunktrunktrunktrunklimited connectivity
accessaccessaccesslimited connectivityaccess

The default on many current Catalyst switches, including the 2960, is dynamic auto, and auto plus auto gives an access link. That surprises people: two new switches cabled together do not trunk until you configure one side. Professionals do not rely on negotiation at all; they hard code every port as access or trunk and turn DTP off with switchport nonegotiate.

3.4.05

VLAN hopping and how to stop it

Practise the whole SW1 configuration in the simulator, then build both switches in Packet Tracer.

console: SW1 (SW1 VLANs and trunk)

Missions 0/9

    Simplified IOS simulator in your browser. It teaches the commands; Packet Tracer and real gear have many more.

    Flashcards: do you remember?

    Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

    Quick quiz

    Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

    Q1Two new 2960s with default settings are cabled together. What forms?

    Q2What does the native VLAN carry?

    Q3Which pair of commands hardens a user port?

    Q4Double tagging works only when the attacker is in which VLAN?

    Q5PCs in VLAN 10 on SW1 and SW2 cannot talk. The trunk is up. First thing to check?

    Q6Why move unused ports to a parking VLAN and shut them?

    0 / 6

    Hands-on lab

    Cisco Packet Tracer lab40 minutessimulated network

    Packet Tracer lab 3.4: two switch VLANs with a hardened trunk

    You need: Cisco Packet Tracer (free with a Cisco Networking Academy account; version 9.0.1 was the current download on the NetAcad Resource Hub when this lesson was written). Devices: 2 x 2960-24TT, 4 x PC-PT, and optionally 1 x IP Phone (7960).

    Topology and addressing

    Lab 3.4 topology: staff, voice and guest ports on two switches joined by an 802.1Q trunkFa0/2Fa0/3Fa0/12Gi0/1Gi0/1Fa0/2Fa0/12PC-Staff1VLAN 10IP-Phone1voice 30PC-Guest1VLAN 20SW1SW2PC-Staff2VLAN 10PC-Guest2VLAN 20
    Staff, phone and guest ports on SW1, staff and guest ports on SW2, and an 802.1Q trunk between their Gi0/1 ports.
    Addressing table
    DeviceInterfaceIPv4 address / prefixDefault gateway or note
    PC-Staff1Fa0192.168.10.11/24VLAN 10, no gateway yet
    PC-Staff2Fa0192.168.10.12/24VLAN 10
    PC-Guest1Fa0192.168.20.11/24VLAN 20
    PC-Guest2Fa0192.168.20.12/24VLAN 20
    1. Create the VLANs on both switches

      SW1(config)#vlan 10
      SW1(config-vlan)#name STAFF
      SW1(config-vlan)#vlan 20
      SW1(config-vlan)#name GUEST
      SW1(config-vlan)#vlan 30
      SW1(config-vlan)#name VOICE
      SW1(config-vlan)#vlan 99
      SW1(config-vlan)#name NATIVE
      SW1(config-vlan)#vlan 999
      SW1(config-vlan)#name PARKING
    2. Access, voice and parking ports

      SW1(config)#interface range Fa0/1 - 10
      SW1(config-if-range)#switchport mode access
      SW1(config-if-range)#switchport access vlan 10
      SW1(config-if-range)#switchport nonegotiate
      SW1(config-if-range)#interface Fa0/3
      SW1(config-if)#switchport voice vlan 30
      SW1(config-if)#interface range Fa0/11 - 20
      SW1(config-if-range)#switchport mode access
      SW1(config-if-range)#switchport access vlan 20
      SW1(config-if-range)#switchport nonegotiate
      SW1(config-if-range)#interface range Fa0/21 - 24
      SW1(config-if-range)#switchport mode access
      SW1(config-if-range)#switchport access vlan 999
      SW1(config-if-range)#shutdown
    3. See what DTP did by default

      SW1#show interfaces Gi0/1 switchport

      Read Administrative Mode and Operational Mode before you change anything.

    4. Harden the trunk (both switches)

      SW1(config)#interface Gi0/1
      SW1(config-if)#switchport mode trunk
      SW1(config-if)#switchport trunk native vlan 99
      SW1(config-if)#switchport trunk allowed vlan 10,20,30,99
      SW1(config-if)#switchport nonegotiate
    5. Test

      PC-Staff1 pings PC-Staff2: it works. PC-Staff1 pings PC-Guest2: it fails, because they are in different VLANs and subnets and there is no router yet (lesson 3.6).

    6. Break it on purpose

      On SW2 only, set switchport trunk native vlan 1. Watch the console for the native VLAN mismatch message, then set it back to 99.

    7. Verify

      SW1#show vlan brief
      SW1#show interfaces trunk
      SW1#show interfaces Gi0/1 switchport
      SW1#show interfaces Fa0/3 switchport

    You are done when: show interfaces trunk shows Gi0/1 in mode on, 802.1q, native VLAN 99 and allowed 10,20,30,99; staff PCs reach each other across the trunk; guests cannot reach staff.

    Packet Tracer limits and notes

    • Packet Tracer does not let you craft double tagged frames or DTP attacks, so the hopping attacks stay theory here. That is fine for a defence first course.
    • vlan dot1q tag native (tagging the native VLAN) is UNVERIFIED in Packet Tracer and likely not supported on the 2960 image.
    • The exact text of the CDP native VLAN mismatch message in Packet Tracer is UNVERIFIED; on real IOS it reads like %CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on ....
    • Packet Tracer simulates a subset of IOS. If a command here is rejected in your version, note it, skip that step and carry on; the concept still applies to real Cisco gear.

    Download the lab checklist (.txt) Print it or keep it open beside Packet Tracer.

    Key takeaways

    • A VLAN is a broadcast domain, usually one subnet.
    • Access ports are untagged; trunks tag with 802.1Q except the native VLAN.
    • auto plus auto is an access link; hard code ports and use nonegotiate.
    • Native VLAN unused, users out of VLAN 1, trunks carry only what they need.
    • Park and shut unused ports.

    Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.