Intermediate · Switching and VLANs · topic 22 of 57 · 30 min
Trunks and 802.1Q tagging
Explanation
Why trunks?
Say VLANs 10, 20 and 30 exist on two switches, one on each floor. Without trunks you would need one cable per VLAN between the switches: three cables for three VLANs, fifty cables for fifty VLANs. A trunk is a single link that carries the traffic of many VLANs. To keep the VLANs apart on that shared cable, each frame is labelled with its VLAN number.
The 802.1Q tag
IEEE 802.1Q is the standard way to tag frames. The switch inserts a 4-byte tag between the source MAC address and the EtherType field of the Ethernet frame, and recalculates the frame check sequence (FCS). The receiving switch reads the tag, removes it, and delivers the frame in the right VLAN.
| Field | Size | Meaning |
|---|---|---|
| TPID (Tag Protocol Identifier) | 16 bits | Always 0x8100. It tells the receiver "a VLAN tag follows". |
| PCP (Priority Code Point) | 3 bits | Priority 0 to 7, used by QoS (for example voice gets 5). |
| DEI (Drop Eligible Indicator) | 1 bit | Marks frames that may be dropped first when the link is busy. |
| VID (VLAN Identifier) | 12 bits | The VLAN number. 12 bits give 4096 values; 0 and 4095 are reserved, so 4094 are usable. |
Cisco also had an older protocol of its own, ISL, which wrapped the whole frame instead of adding a tag. It is obsolete and most current switches support only 802.1Q.
The native VLAN
On an 802.1Q trunk, frames in one special VLAN, the native VLAN, are sent without a tag. Any untagged frame that arrives on the trunk is placed in the native VLAN. By default the native VLAN is VLAN 1.
The native VLAN must be the same on both ends. If SW1 uses native VLAN 1 and SW2 uses native VLAN 99, an untagged frame from VLAN 1 on SW1 lands in VLAN 99 on SW2: traffic leaks between VLANs. CDP notices this and logs a "native VLAN mismatch" message.
For security, change the native VLAN to an unused VLAN (for example 999) on both ends, and never put users in it. Attackers can abuse the default native VLAN with a "double tagging" VLAN hopping attack, sending a frame with two tags so that it ends up in a VLAN they should not reach.
Configuring a trunk
SW1(config)# interface gigabitEthernet 0/1
SW1(config-if)# switchport trunk encapsulation dot1q
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk native vlan 999
SW1(config-if)# switchport trunk allowed vlan 10,20,30
SW1(config-if)# switchport nonegotiateThe allowed VLAN list and the add trap
By default a trunk carries all VLANs. switchport trunk allowed vlan limits it to a list. The catch: giving a plain list REPLACES the old list.
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# switchport trunk allowed vlan 30
! Now ONLY VLAN 30 is allowed. VLANs 10 and 20 just went down on this trunk.
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# switchport trunk allowed vlan add 30
! Correct: VLANs 10, 20 and 30 are allowed.DTP: trunks that negotiate themselves
DTP (Dynamic Trunking Protocol) is a Cisco protocol that lets two switch ports agree whether to become a trunk. The port modes are: access (never a trunk), trunk (always a trunk), dynamic desirable (actively asks to trunk) and dynamic auto (trunks only if the other side asks).
| access | dynamic auto | dynamic desirable | trunk | |
|---|---|---|---|---|
| access | access | access | access | mismatch |
| dynamic auto | access | access | trunk | trunk |
| dynamic desirable | access | trunk | trunk | trunk |
| trunk | mismatch | trunk | trunk | trunk |
The trap: dynamic auto plus dynamic auto gives an access link, because both sides wait for the other to ask. Many current Cisco switches use dynamic auto by default, so two new switches cabled together often do not form a trunk. switchport nonegotiate stops DTP frames entirely; use it with a hard-coded trunk.
Verifying: show interfaces trunk
SW1# show interfaces trunk
Port Mode Encapsulation Status Native vlan
Gi0/1 on 802.1q trunking 999
Port Vlans allowed on trunk
Gi0/1 10,20,30
Port Vlans allowed and active in management domain
Gi0/1 10,20,30
Port Vlans in spanning tree forwarding state and not pruned
Gi0/1 10,20,30Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Trunks and 802.1Q tagging · 1/8
In this lesson you will learn how one cable can carry many VLANs: the trunk.
Prefer a video by a teacher? Find free videos on “802.1Q trunk native vlan DTP explained ccna” on YouTube ↗
In real life: Two floors of a BPO in Gurugram
A BPO has voice agents on floor 3 and floor 4, with VLANs 10 (agents), 20 (supervisors) and 50 (voice) on both floors. One fibre trunk links the two floor switches and carries all three VLANs. One night an engineer adds a new VLAN 60 for a client, types switchport trunk allowed vlan 60 without add, and the calls of 300 agents drop. The fix takes ten seconds: switchport trunk allowed vlan 10,20,50,60. The team now uses a change checklist that includes show interfaces trunk before and after.
Practice (0/3 done)
A trunk allows VLANs 10 and 20. An engineer types switchport trunk allowed vlan 30 on it. Which VLANs does the trunk carry now?
Write dtp_result(a, b) for two connected switch ports. Each mode is one of "access", "trunk", "auto" (dynamic auto) or "desirable" (dynamic desirable). Return "trunk", "access" or "mismatch". Rules: access with trunk is a "mismatch"; access with anything else is "access"; auto with auto is "access"; every other pair is "trunk". The order of a and b must not matter.
The 4-byte 802.1Q tag is given as 8 hex digits, for example "8100600A". The first 16 bits are the TPID. The last 16 bits (the TCI) hold PCP (top 3 bits), DEI (next 1 bit) and the VLAN ID (low 12 bits). Write parse_tag(hex_text) that returns a dict with keys "tpid" (an int), "pcp", "dei" and "vlan". Example: "8100600A" gives {"tpid": 33024, "pcp": 3, "dei": 0, "vlan": 10}.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Inter-VLAN routingSwitching and VLANs · same module
- CDP and LLDP: discovering neighboursSwitching and VLANs · same module
- Layer 2 security: port security, DHCP snooping, DAINetwork security
- EtherChannel: bundling linksSpanning Tree and EtherChannel
- Troubleshooting tools and common faultsTroubleshooting and the CCNA exam
- Root bridge election, root ports and designated portsSpanning Tree and EtherChannel
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
How many bytes does an 802.1Q tag add to a frame?
Answer: 4
The 802.1Q tag is 4 bytes: a 2-byte TPID and a 2-byte TCI.
How are frames in the native VLAN sent on an 802.1Q trunk?
Answer: Untagged
The native VLAN is the one VLAN whose frames cross the trunk without a tag.
Two new switches use dynamic auto on the ports that link them. What forms?
Answer: An access link
Both sides wait for the other to ask, so neither asks and the link stays access.
Why do 12 bits of VLAN ID give 4094 usable VLANs, not 4096?
Answer: The values 0 and 4095 are reserved
12 bits give 0 to 4095. The values 0 and 4095 are reserved, leaving 1 to 4094.
Which command shows the native VLAN and the allowed VLANs of each trunk?
Answer: show interfaces trunk
show interfaces trunk lists each trunk with its mode, encapsulation, native VLAN and allowed VLANs.
Which command makes Fa0/5 an access port in VLAN 30 (after switchport mode access)?Related
Answer: switchport access vlan 30
switchport access vlan 30 sets the data VLAN of an access port.
A PC in VLAN 10 sends a packet to a PC in VLAN 20. Where does it send the frame first?Related
Answer: To its default gateway
The other PC is on a different subnet, so the PC sends the packet to its default gateway, which routes it.
From Inter-VLAN routing
Which configuration helps prevent VLAN hopping by switch spoofing?Related
Answer: switchport mode access on user ports
An access port does not negotiate a trunk, so a host cannot use DTP to turn it into one.
Where should you configure the trunk settings of an EtherChannel?Related
Answer: On interface port-channel
Configure the logical port-channel interface; IOS applies the settings to the members so they stay consistent.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Switching and VLANs” before its exam: Inter-VLAN routing, CDP and LLDP: discovering neighbours, Switch management and interface troubleshooting.
- Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.