Skip to main content

PeakHop blog

How to Configure VLANs and Trunks on Cisco Switches (With Lab)

Configure VLANs, access ports, and 802.1Q trunks on Cisco switches step by step, with the show output to expect and fixes for the four common trunk faults.

By PeakHop Editorial Team · Published

To configure a trunk on a Cisco switch, go to the interface, set switchport mode trunk, and limit the link to the VLANs it needs with switchport trunk allowed vlan. On older switches that also support ISL, add switchport trunk encapsulation dot1q first. Configure the other end the same way, then check both with show interfaces trunk. Most trunk problems come down to four faults: a VLAN missing from the allowed list, a native VLAN mismatch, both ends left in dynamic auto, or a VLAN that doesn't exist on one of the switches.

This guide builds a small network from scratch: two VLANs, access ports for two PCs on each switch, and a trunk between the switches. The output shown is example IOS output from PeakHop's lab environment, so interface names and spacing on your switch may differ slightly.

  PC-A (VLAN 10)                 PC-C (VLAN 10)
       |                              |
    Gi1/0/1                        Gi1/0/1
     [ SW1 ]Gi1/0/24 ===trunk=== Gi1/0/24[ SW2 ]
    Gi1/0/2                        Gi1/0/2
       |                              |
  PC-B (VLAN 20)                 PC-D (VLAN 20)

VLANs, access ports, and trunks in one minute

A VLAN splits one switch into separate broadcast domains. An access port belongs to one VLAN and sends frames untagged, which is what a PC expects. A trunk port carries many VLANs over one link, adding an 802.1Q tag to each frame so the switch at the other end knows which VLAN it belongs to. The one exception is the native VLAN, whose frames cross the trunk untagged. By default the native VLAN is VLAN 1 (Cisco).

Step 1: Create and name the VLANs

Create each VLAN on every switch that has ports in it or carries it across a trunk. In this network, that's both switches:

SW1# configure terminal
SW1(config)# vlan 10
SW1(config-vlan)# name SALES
SW1(config-vlan)# vlan 20
SW1(config-vlan)# name ENGINEERING
SW1(config-vlan)# vlan 99
SW1(config-vlan)# name NATIVE
SW1(config-vlan)# exit

Repeat on SW2. VLAN 99 will be the native VLAN in Step 4. A switch drops traffic for a VLAN it doesn't have, even if the trunk allows it, so a VLAN missing on one switch is a common fault.

Step 2: Configure the access ports

Make each PC port an access port in the right VLAN:

SW1(config)# interface GigabitEthernet1/0/1
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 10
SW1(config-if)# interface GigabitEthernet1/0/2
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
SW1(config-if)# end

Setting switchport mode access stops the port from negotiating a trunk with whatever is plugged in. Check the result with show vlan brief:

SW1# show vlan brief

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Gi1/0/3, Gi1/0/4, Gi1/0/5
10   SALES                            active    Gi1/0/1
20   ENGINEERING                      active    Gi1/0/2
99   NATIVE                           active

Trunk ports don't appear in show vlan brief, so Gi1/0/24 won't show up here once it's a trunk. That's normal. Use show interfaces trunk for trunks.

Step 3: Build the trunk

Configure the uplink as a trunk and allow only the VLANs that need to cross it:

SW1(config)# interface GigabitEthernet1/0/24
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk allowed vlan 10,20,99

On a switch that supports both ISL and 802.1Q, such as many older Catalyst models, IOS rejects switchport mode trunk until you choose the encapsulation. Enter switchport trunk encapsulation dot1q first. Current Catalyst switches such as the 9300 use 802.1Q on every Ethernet interface, so the command isn't needed there.

By default a trunk allows all VLANs. Limiting it keeps broadcasts for VLANs a switch doesn't use off the link. Configure SW2's Gi1/0/24 the same way, because both ends of a trunk should match.

Step 4: Set the native VLAN (optional)

Many networks move the native VLAN off VLAN 1 to an unused VLAN, so no user traffic crosses the trunk untagged:

SW1(config-if)# switchport trunk native vlan 99

Set the same native VLAN on both ends. Cisco says the native VLAN must be the same on both ends of an 802.1Q trunk, and a mismatch can cause spanning-tree loops (Cisco). If you change it on one switch first, expect a native VLAN mismatch message from CDP until you fix the other end.

Step 5: Verify with show interfaces trunk

Run this on both switches after your last change:

SW1# show interfaces trunk

Port        Mode             Encapsulation  Status        Native vlan
Gi1/0/24    on               802.1q         trunking      99

Port        Vlans allowed on trunk
Gi1/0/24    10,20,99

Port        Vlans allowed and active in management domain
Gi1/0/24    10,20,99

Port        Vlans in spanning tree forwarding state and not pruned
Gi1/0/24    10,20,99

Read it section by section. Each one answers a different question:

  1. Mode, encapsulation, status, native VLAN. Is the port trunking, and which native VLAN does it use? Mode "on" means switchport mode trunk. Compare the native VLAN with the other switch.
  2. Vlans allowed on trunk. What does the allowed list permit? A VLAN missing here is an allowed-list problem.
  3. Allowed and active in management domain. Which allowed VLANs actually exist on this switch? A VLAN in section 2 but not here hasn't been created on this switch.
  4. Spanning tree forwarding and not pruned. Which VLANs are really forwarding on this link? A VLAN in section 3 but not here is being blocked by spanning tree or pruned.

If a VLAN won't cross the trunk, the first section it drops out of tells you where to look.

Step 6: Save the configuration

SW1# copy running-config startup-config

Do the same on SW2. Then test: PC-A should reach PC-C in VLAN 10, and PC-B should reach PC-D in VLAN 20. PCs in different VLANs can't reach each other without a router or Layer 3 switch, which is expected.

Troubleshooting: the four common trunk faults

FaultSymptomWhat shows itFix
VLAN missing from allowed listOne VLAN can't cross the link, others workshow interfaces trunk: VLAN absent from "Vlans allowed on trunk"switchport trunk allowed vlan add <vlan>
Native VLAN mismatchCDP mismatch messages; untagged traffic leaks across VLANsshow interfaces trunk: different native VLAN on each endSet the same switchport trunk native vlan on both ends
Both ends in dynamic autoNo trunk forms; the ports act as access portsshow interfaces trunk shows nothing for the portSet switchport mode trunk on at least one end, ideally both
VLAN not created on one switchThat VLAN fails across the linkVLAN in "allowed" but not in "allowed and active"Create the VLAN on that switch

The dynamic auto fault comes from how Dynamic Trunking Protocol (DTP) negotiates. A port in dynamic auto only becomes a trunk if the other end is set to trunk or dynamic desirable, and Cisco lists dynamic auto as the default on its Catalyst 9300 interfaces (Cisco). Two auto ports both wait for the other, so neither becomes a trunk. Configuring trunks explicitly avoids the problem, and switchport nonegotiate stops the port sending DTP frames at all.

The allowed VLAN trap

This is the mistake that takes VLANs off live trunks. Say the trunk allows 10, 20, and 99, and you need to add VLAN 30. If you type:

SW1(config-if)# switchport trunk allowed vlan 30

the list becomes just VLAN 30, and VLANs 10, 20, and 99 stop crossing the link:

Port        Vlans allowed on trunk
Gi1/0/24    30

The plain form replaces the whole list. To add one VLAN, use add:

SW1(config-if)# switchport trunk allowed vlan add 30
Port        Vlans allowed on trunk
Gi1/0/24    10,20,30,99

remove takes VLANs off the list the same way, so get into the habit of always typing add or remove on a trunk that's already in use.

Practice it yourself

You don't need switches to practice this. Cisco Packet Tracer is free with a Cisco Networking Academy account, and our guide to practicing Cisco CLI without equipment compares the options. For Network+, VLANs and trunks fall under objective 2.2, one of the scenario objectives covered in our Network+ objectives guide. Our Network+ labs guide covers hands-on practice for it.

Test yourself

  1. 1.A trunk currently allows VLANs 10 and 20. An engineer enters "switchport trunk allowed vlan 30" on it. Which VLANs does the trunk allow now?

  2. 2.In show interfaces trunk, VLAN 40 appears under "Vlans allowed on trunk" but not under "Vlans allowed and active in management domain". What is the most likely cause?

  3. 3.What is the native VLAN on a Cisco 802.1Q trunk by default?

  4. 4.Two connected switch ports are both left in dynamic auto mode. What happens?

  5. 5.Which commands put a port connected to a PC in VLAN 20?

0 of 5 answered.

Frequently asked questions

What's the difference between an access port and a trunk port?

An access port carries one VLAN and sends frames untagged, for end devices such as PCs and printers. A trunk port carries many VLANs between switches, routers, or servers, tagging frames with 802.1Q so each VLAN stays separate.

Does the native VLAN have to match on both ends?

Yes. Cisco says the native VLAN should be the same on both ends of an 802.1Q trunk, and a mismatch can cause spanning-tree loops. CDP also reports a native VLAN mismatch when it detects one.

Do I need switchport trunk encapsulation dot1q?

Only on switches that support both ISL and 802.1Q, where IOS won't accept switchport mode trunk until you choose. Current Catalyst switches use 802.1Q only, and don't need it.

Why does show interfaces trunk show nothing?

The port isn't trunking. Check the mode on both ends with show interfaces <interface> switchport. Two ports in dynamic auto, or one end set to access, won't form a trunk.

Should the native VLAN be in the allowed list?

If anything uses the native VLAN, keep it in the allowed list on both ends, as in this guide's example. Removing it from the list stops that VLAN's traffic crossing the trunk.

Practice VLANs and trunks with PeakHop

PeakHop's CCNA course includes Cisco CLI labs for exactly this task: creating named VLANs and access ports, building trunks across three switches with allowed lists, setting a non-default native VLAN, and bundling trunks with EtherChannel. Your progress updates as you type commands, and each lab checks the result. Network+ learners get a VLAN trunk repair simulation, where you find out why one department can't reach its server while another still can, then fix the port and the trunk.

See the CCNA study guide and the Network+ study guide for what each course covers.

Start studying with PeakHop

Sources

Related posts

Back to PeakHop