Skip to content

Intermediate · Switching and VLANs · topic 22 of 57 · 30 min

Trunks and 802.1Q tagging

Explanation

A trunk is a link that carries many VLANs at once. Each frame gets a 4-byte 802.1Q tag holding its VLAN number, so the switch at the other end knows which VLAN it belongs to. Frames in the native VLAN travel untagged, so the native VLAN must match on both ends. Use switchport mode trunk, control the VLANs with switchport trunk allowed vlan (and do not forget the add keyword), and verify with show interfaces trunk.

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.

Think of it like this: A trunk is like a courier van running between two branch offices. It carries parcels for many departments in one trip. Each parcel has a sticker saying "Accounts" or "HR", so the receiving office knows which department to deliver it to. The sticker is the 802.1Q tag.

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.

FieldSizeMeaning
TPID (Tag Protocol Identifier)16 bitsAlways 0x8100. It tells the receiver "a VLAN tag follows".
PCP (Priority Code Point)3 bitsPriority 0 to 7, used by QoS (for example voice gets 5).
DEI (Drop Eligible Indicator)1 bitMarks frames that may be dropped first when the link is busy.
VID (VLAN Identifier)12 bitsThe 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

output
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 nonegotiate
Cisco IOS: the first line is only needed (and only accepted) on switches that also support ISL, such as the 3560. On a 2960 skip it.

The 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.

output
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.
Cisco IOS: other keywords are remove, except, all and none.
Careful: Forgetting add is one of the most common outages in real networks. An engineer adds VLAN 30 to a busy trunk, types the command without add, and every other VLAN on that link stops at once. Always type add (or remove), and check with show interfaces trunk before and after.

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).

accessdynamic autodynamic desirabletrunk
accessaccessaccessaccessmismatch
dynamic autoaccessaccesstrunktrunk
dynamic desirableaccesstrunktrunktrunk
trunkmismatchtrunktrunktrunk

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.

Tip: Best practice: never rely on DTP. Hard-code switchport mode trunk on trunk links and switchport mode access on user ports. DTP on user ports can let an attacker negotiate a trunk and see every VLAN.

Verifying: show interfaces trunk

output
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,30
Cisco IOS: Mode "on" means switchport mode trunk. Check the native VLAN and the allowed list on both switches.

Need 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

Trunks and 802.1Q

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)

Task 1 · Question

A trunk allows VLANs 10 and 20. An engineer types switchport trunk allowed vlan 30 on it. Which VLANs does the trunk carry now?

Task 2 · Code · Python

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.

Task 3 · Code · Python

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

Question 1

1.How many bytes does an 802.1Q tag add to a frame?

Question 2

2.How are frames in the native VLAN sent on an 802.1Q trunk?

Question 3

3.Two new switches use dynamic auto on the ports that link them. What forms?

Question 4

4.Why do 12 bits of VLAN ID give 4094 usable VLANs, not 4096?

Question 5

5.Which command shows the native VLAN and the allowed VLANs of each trunk?

Read more (free)

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.

From VLANs: what they are and why we use them

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.

From Layer 2 security: port security, DHCP snooping, DAI

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.

From EtherChannel: bundling links

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

  1. 3 more topics in “Switching and VLANs” before its exam: Inter-VLAN routing, CDP and LLDP: discovering neighbours, Switch management and interface troubleshooting.
  2. Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.

← Previous: VLANs: what they are and why we use them