On this page 13 sections
  1. 1. Lab topology and switching basics
  2. 2. Create VLANs and assign access ports
  3. 3. Configure the switch-to-switch trunk
  4. 4. Test Layer 2 connectivity
  5. 5. Route between VLANs with router-on-a-stick
  6. 6. Native VLAN and allowed-list changes
  7. 7. Alternative: route on a Layer 3 switch
  8. 8. Routed ports on a multilayer switch
  9. 9. STP and Rapid PVST+
  10. 10. PortFast and BPDU Guard
  11. 11. LACP EtherChannel
  12. 12. Verification and common failures
  13. 13. Cisco references
01

1. Lab topology and switching basics

Example: Sales uses VLAN 10 and IT uses VLAN 20. Each department has a PC on each of two switches. First connect PCs within the same VLAN; then add routing between departments.

A switch learns source MAC addresses on its ports and uses destination MAC addresses to forward frames within a VLAN. Each VLAN is a separate broadcast domain. Communication between different VLANs needs a router or Layer 3 switch.

Use fresh IOS / IOS XE lab devices and adapt interface names to your model. Prompts identify the device and mode. Type only the text after the prompt; PC prompts identify the endpoint terminal. Packet Tracer and different switch models support different command subsets.

The main lab uses R1 for routing. Section 7 is a separate Layer 3 switch alternative; do not apply both gateway designs to the same lab.

Main lab — topology and addresses, reference only
PC1 -- Fa0/1 [SW1] Gi0/2 ------- Gi0/1 [SW2] Fa0/1 -- PC3
PC2 -- Fa0/2   |                              Fa0/2 -- PC4
            Gi0/1
              |
            Gi0/0
             [R1]

PC   VLAN  IPv4 address       Mask             Gateway
PC1  10    192.168.10.10     255.255.255.0    192.168.10.1
PC3  10    192.168.10.30     255.255.255.0    192.168.10.1
PC2  20    192.168.20.20     255.255.255.0    192.168.20.1
PC4  20    192.168.20.40     255.255.255.0    192.168.20.1

SW1 Gi0/2 <-> SW2 Gi0/1: trunk carrying VLANs 10,20
SW1 Gi0/1 <-> R1 Gi0/0:  trunk carrying VLANs 10,20
02

2. Create VLANs and assign access ports

Example: on both switches, Fa0/1 connects to a Sales PC and Fa0/2 connects to an IT PC. Configure each PC with the address, mask and gateway in the plan.

An access port carries one untagged data VLAN. The PC sends ordinary Ethernet frames; the switch associates them with the configured VLAN.

  • vlan 10: create or select VLAN 10.
  • name SALES: give the VLAN a readable label.
  • switchport mode access: explicitly configure an access port.
  • switchport access vlan 10: place the port in VLAN 10.
  • no shutdown: enable the port.
  • show vlan brief: check VLANs and access-port membership.

Create the VLANs on both switches. This lab uses manual VLAN configuration and does not depend on VTP. VTP distributes VLAN information; it does not provide inter-VLAN routing.

SW1 — SW1 and SW2 — run separately on each switch
SW1# configure terminal
SW1(config)# vlan 10
SW1(config-vlan)# name SALES
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# name IT
SW1(config-vlan)# exit
SW1(config)# interface FastEthernet0/1
SW1(config-if)# description SALES_PC
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 10
SW1(config-if)# no shutdown
SW1(config-if)# exit
SW1(config)# interface FastEthernet0/2
SW1(config-if)# description IT_PC
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
SW1(config-if)# no shutdown
SW1(config-if)# end
SW2 — SW1 and SW2 — run separately on each switch
SW2# configure terminal
SW2(config)# vlan 10
SW2(config-vlan)# name SALES
SW2(config-vlan)# exit
SW2(config)# vlan 20
SW2(config-vlan)# name IT
SW2(config-vlan)# exit
SW2(config)# interface FastEthernet0/1
SW2(config-if)# description SALES_PC
SW2(config-if)# switchport mode access
SW2(config-if)# switchport access vlan 10
SW2(config-if)# no shutdown
SW2(config-if)# exit
SW2(config)# interface FastEthernet0/2
SW2(config-if)# description IT_PC
SW2(config-if)# switchport mode access
SW2(config-if)# switchport access vlan 20
SW2(config-if)# no shutdown
SW2(config-if)# end
SW1 — SW1 and SW2 — verify access ports
SW1# show vlan brief
SW1# show interfaces FastEthernet0/1 switchport
SW1# show interfaces FastEthernet0/2 switchport
SW2 — SW1 and SW2 — verify access ports
SW2# show vlan brief
SW2# show interfaces FastEthernet0/1 switchport
SW2# show interfaces FastEthernet0/2 switchport
03

3. Configure the switch-to-switch trunk

Example: PC1 and PC3 belong to VLAN 10 but are on different switches. The SW1–SW2 link must carry VLANs 10 and 20.

A trunk transports multiple VLANs. 802.1Q adds a VLAN tag to frames, except for native-VLAN traffic under the usual untagged-native configuration. Both ends must agree on the native VLAN.

  • switchport mode trunk: explicitly make the link a trunk.
  • switchport trunk allowed vlan 10,20: replace the allowed VLAN list with VLANs 10 and 20.
  • switchport nonegotiate: disable DTP negotiation; configure the peer as a static trunk too.
  • show interfaces trunk: display operational trunks and allowed/forwarding VLANs.

DTP (Dynamic Trunking Protocol) negotiates trunking on supporting Cisco ports. Static configuration makes the intended port role explicit. Some older switches require switchport trunk encapsulation dot1q before trunk mode; fixed-802.1Q models do not offer that command.

The main lab leaves native VLAN 1 unchanged on both ends and carries user traffic tagged in VLANs 10 and 20.

SW1 — trunk to SW2
SW1# configure terminal
SW1(config)# interface GigabitEthernet0/2
SW1(config-if)# description TRUNK_to_SW2_Gi0/1
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# switchport nonegotiate
SW1(config-if)# no shutdown
SW1(config-if)# end
SW2 — trunk to SW1
SW2# configure terminal
SW2(config)# interface GigabitEthernet0/1
SW2(config-if)# description TRUNK_to_SW1_Gi0/2
SW2(config-if)# switchport mode trunk
SW2(config-if)# switchport trunk allowed vlan 10,20
SW2(config-if)# switchport nonegotiate
SW2(config-if)# no shutdown
SW2(config-if)# end
SW1 — SW1 and SW2 — verify trunks
SW1# show interfaces trunk
SW1# show mac address-table dynamic
SW2 — SW1 and SW2 — verify trunks
SW2# show interfaces trunk
SW2# show mac address-table dynamic
04

4. Test Layer 2 connectivity

Example: test PC1 to PC3 before configuring R1. Both are in VLAN 10, so this traffic does not need a gateway.

  • ping 192.168.10.30: test PC3 from PC1 across the trunk.
  • show mac address-table dynamic vlan 10: inspect MAC addresses learned in VLAN 10.

Expected: PC1 reaches PC3, and PC2 reaches PC4. PC1 cannot yet reach PC2 because inter-VLAN routing is not configured.

On SW1, PC1's MAC should appear on Fa0/1 and PC3's MAC on Gi0/2 after traffic has passed. A trunk normally does not appear as an access member in show vlan brief; inspect show interfaces trunk instead.

PC1 — test the remote Sales PC
PC1> ping 192.168.10.30
PC2 — test the remote IT PC
PC2> ping 192.168.20.40
SW1 — inspect learned MAC addresses
SW1# show mac address-table dynamic vlan 10
SW1# show mac address-table dynamic vlan 20
05

5. Route between VLANs with router-on-a-stick

Example: PC1 needs to reach PC2. Use one physical R1 interface with a logical subinterface for each VLAN. This design is called router-on-a-stick.

  • interface GigabitEthernet0/0.10: create a logical subinterface; .10 is a naming convention, not the VLAN assignment itself.
  • encapsulation dot1Q 10: associate the subinterface with tagged VLAN 10 traffic.
  • ip address 192.168.10.1 255.255.255.0: make that subinterface the VLAN 10 gateway.
  • no ip address: remove the parent interface's IPv4 address; this lab puts gateway addresses on subinterfaces.

Enable the physical parent interface and configure SW1's router-facing port as a trunk. R1 does not use switchport commands on its routed Ethernet interface.

Use the PC gateways in the plan. Routing connects the VLANs; restricting departmental access would require an ACL.

SW1 — trunk to R1
SW1# configure terminal
SW1(config)# interface GigabitEthernet0/1
SW1(config-if)# description TRUNK_to_R1_Gi0/0
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# switchport nonegotiate
SW1(config-if)# no shutdown
SW1(config-if)# end
R1 — configure VLAN gateways
R1# configure terminal
R1(config)# interface GigabitEthernet0/0
R1(config-if)# no ip address
R1(config-if)# no shutdown
R1(config-if)# exit
R1(config)# interface GigabitEthernet0/0.10
R1(config-subif)# encapsulation dot1Q 10
R1(config-subif)# ip address 192.168.10.1 255.255.255.0
R1(config-subif)# exit
R1(config)# interface GigabitEthernet0/0.20
R1(config-subif)# encapsulation dot1Q 20
R1(config-subif)# ip address 192.168.20.1 255.255.255.0
R1(config-subif)# end
R1 — verify connected networks
R1# show ip interface brief
R1# show ip route connected
PC1 — test gateway and inter-VLAN routing
PC1> ping 192.168.10.1
PC1> ping 192.168.20.20
PC1> ping 192.168.20.40
06

6. Native VLAN and allowed-list changes

Example: optionally move the native VLAN of the SW1–SW2 trunk to unused VLAN 999. Apply the change to both ends. This example does not change the separate SW1–R1 trunk.

  • switchport trunk native vlan 999: associate untagged data traffic on this trunk with VLAN 999 under the default native-tagging behavior.
  • switchport trunk allowed vlan add 999: add VLAN 999 without replacing the existing list.
  • switchport trunk allowed vlan remove 999: remove VLAN 999 from the allowed list when required; this does not change the native-VLAN setting.

Create VLAN 999 on both switches and leave it without user access ports. A native-VLAN mismatch can associate untagged traffic with the wrong VLAN and trigger spanning-tree consistency problems.

Using switchport trunk allowed vlan 999 without add would replace the list and remove VLANs 10 and 20.

SW1 — optional native-VLAN change toward SW2
SW1# configure terminal
SW1(config)# vlan 999
SW1(config-vlan)# name UNUSED_NATIVE
SW1(config-vlan)# exit
SW1(config)# interface GigabitEthernet0/2
SW1(config-if)# switchport trunk native vlan 999
SW1(config-if)# switchport trunk allowed vlan add 999
SW1(config-if)# end
SW2 — matching native-VLAN change toward SW1
SW2# configure terminal
SW2(config)# vlan 999
SW2(config-vlan)# name UNUSED_NATIVE
SW2(config-vlan)# exit
SW2(config)# interface GigabitEthernet0/1
SW2(config-if)# switchport trunk native vlan 999
SW2(config-if)# switchport trunk allowed vlan add 999
SW2(config-if)# end
07

7. Alternative: route on a Layer 3 switch

Example: in a separate lab, connect PC1 to MLS1 Fa0/1 and PC2 to MLS1 Fa0/2. MLS1 replaces R1 as the gateway for VLANs 10 and 20. Do not retain another device with the same gateway addresses on those VLANs.

An SVI (Switch Virtual Interface) is a logical Layer 3 interface for a VLAN. A multilayer switch can route between SVIs when routing is enabled and supported by its image/model.

  • ip routing: enable IPv4 routing on the multilayer switch.
  • interface vlan 10: select VLAN 10's SVI.
  • ip address: assign the SVI's gateway address and mask.
  • show ip route connected: confirm the switch has connected routes for both VLANs.

Each SVI needs its VLAN to exist and an active member port forwarding traffic. ip default-gateway is not the routing configuration for a switch operating with IP routing enabled.

MLS1 — standalone two-VLAN routing lab
MLS1# configure terminal
MLS1(config)# ip routing
MLS1(config)# vlan 10
MLS1(config-vlan)# name SALES
MLS1(config-vlan)# exit
MLS1(config)# vlan 20
MLS1(config-vlan)# name IT
MLS1(config-vlan)# exit
MLS1(config)# interface FastEthernet0/1
MLS1(config-if)# switchport mode access
MLS1(config-if)# switchport access vlan 10
MLS1(config-if)# no shutdown
MLS1(config-if)# exit
MLS1(config)# interface FastEthernet0/2
MLS1(config-if)# switchport mode access
MLS1(config-if)# switchport access vlan 20
MLS1(config-if)# no shutdown
MLS1(config-if)# exit
MLS1(config)# interface vlan 10
MLS1(config-if)# ip address 192.168.10.1 255.255.255.0
MLS1(config-if)# no shutdown
MLS1(config-if)# exit
MLS1(config)# interface vlan 20
MLS1(config-if)# ip address 192.168.20.1 255.255.255.0
MLS1(config-if)# no shutdown
MLS1(config-if)# end
MLS1 — verify; PC1 should now reach PC2
MLS1# show ip interface brief
MLS1# show ip route connected
08

8. Routed ports on a multilayer switch

Example: extend the MLS1 alternative lab with a routed uplink to R2. Use 10.0.0.1/30 on MLS1 Gi0/1 and 10.0.0.2/30 on R2 Gi0/0.

  • no switchport: convert a supported switch port into a routed Layer 3 interface.
  • ip address: assign an address directly to that physical interface.

A routed port does not carry access VLANs or an 802.1Q trunk in this example. This block establishes only the connected uplink; reaching networks beyond it requires routes and a return path.

MLS1 — routed uplink
MLS1# configure terminal
MLS1(config)# interface GigabitEthernet0/1
MLS1(config-if)# no switchport
MLS1(config-if)# ip address 10.0.0.1 255.255.255.252
MLS1(config-if)# no shutdown
MLS1(config-if)# end
R2 — matching routed interface
R2# configure terminal
R2(config)# interface GigabitEthernet0/0
R2(config-if)# ip address 10.0.0.2 255.255.255.252
R2(config-if)# no shutdown
R2(config-if)# end
R2# ping 10.0.0.1
09

9. STP and Rapid PVST+

Example: return to the main SW1–SW2 lab. Make SW1 the preferred spanning-tree root for VLANs 10 and 20.

STP (Spanning Tree Protocol) prevents Layer 2 loops by keeping redundant paths from forwarding simultaneously. Rapid PVST+ provides a rapid spanning-tree instance per VLAN. The root is selected using the lowest bridge ID, including priority and MAC address.

  • spanning-tree mode rapid-pvst: select Rapid PVST+ on a supporting switch.
  • spanning-tree vlan 10,20 root primary: adjust priority to make this switch the intended root under the current topology.
  • spanning-tree vlan 10,20 root secondary: set a backup-root priority; verify the actual election.
  • show spanning-tree vlan 10: inspect the root, port roles and states.

The main lab has one inter-switch link, so no redundant path needs blocking. With additional independent links, an alternate/discarding port can be normal. Changing STP mode or priority can briefly reconverge the topology.

SW1 — preferred root
SW1# configure terminal
SW1(config)# spanning-tree mode rapid-pvst
SW1(config)# spanning-tree vlan 10,20 root primary
SW1(config)# end
SW2 — backup root
SW2# configure terminal
SW2(config)# spanning-tree mode rapid-pvst
SW2(config)# spanning-tree vlan 10,20 root secondary
SW2(config)# end
SW1 — SW1 and SW2 — verify the elected root
SW1# show spanning-tree vlan 10
SW1# show spanning-tree vlan 20
SW2 — SW1 and SW2 — verify the elected root
SW2# show spanning-tree vlan 10
SW2# show spanning-tree vlan 20
10

10. PortFast and BPDU Guard

Example: PC ports should begin forwarding quickly, but an unexpected switch connection should not extend the spanning-tree topology through those ports.

BPDUs (Bridge Protocol Data Units) are spanning-tree control messages exchanged by switches.

  • spanning-tree portfast: let an endpoint port enter forwarding immediately; STP is not disabled.
  • spanning-tree bpduguard enable: place the port into err-disabled state if it receives a BPDU.
  • show interfaces status: identify err-disabled or disconnected ports.

Apply this block only to the PC-facing ports in this lab, not the switch-to-switch links. If BPDU Guard triggers, remove the cause before re-enabling the port with shutdown followed by no shutdown.

SW1 — SW1 and SW2 — protect PC-facing ports
SW1# configure terminal
SW1(config)# interface range FastEthernet0/1 - 2
SW1(config-if-range)# spanning-tree portfast
SW1(config-if-range)# spanning-tree bpduguard enable
SW1(config-if-range)# end
SW2 — SW1 and SW2 — protect PC-facing ports
SW2# configure terminal
SW2(config)# interface range FastEthernet0/1 - 2
SW2(config-if-range)# spanning-tree portfast
SW2(config-if-range)# spanning-tree bpduguard enable
SW2(config-if-range)# end
11

11. LACP EtherChannel

Example: use a separate pair of fresh switches, EC1 and EC2, with Gi0/1 connected to Gi0/1 and Gi0/2 connected to Gi0/2. Bundle both links into one trunk for VLANs 10 and 20.

EtherChannel groups compatible physical links into a logical Port-channel. STP treats the bundle as one link. Traffic is distributed by a hash; one flow normally does not use the combined bandwidth of every member.

  • interface range GigabitEthernet0/1 - 2: configure both member ports together.
  • channel-group 1 mode active: use LACP to negotiate membership in local Port-channel1.
  • interface Port-channel1: configure the logical bundle.
  • show etherchannel summary: check bundle and member status.
  • show lacp neighbor: inspect the peer's LACP information.

LACP forms with active/active or active/passive; passive/passive does not initiate negotiation. Cisco PAgP uses desirable/auto negotiation instead. Static mode on performs no negotiation. This lab uses LACP active at both ends.

Member speed, duplex and Layer 2 settings must be compatible; trunk/native/allowed VLAN settings must agree. Keep members shut while preparing both ends, then enable them. The group number is locally significant and need not match the peer's number.

EC1 — EC1 and EC2 — prepare separately on both switches
EC1# configure terminal
EC1(config)# vlan 10
EC1(config-vlan)# name SALES
EC1(config-vlan)# exit
EC1(config)# vlan 20
EC1(config-vlan)# name IT
EC1(config-vlan)# exit
EC1(config)# interface range GigabitEthernet0/1 - 2
EC1(config-if-range)# shutdown
EC1(config-if-range)# switchport mode trunk
EC1(config-if-range)# switchport trunk allowed vlan 10,20
EC1(config-if-range)# channel-group 1 mode active
EC1(config-if-range)# exit
EC1(config)# interface Port-channel1
EC1(config-if)# switchport mode trunk
EC1(config-if)# switchport trunk allowed vlan 10,20
EC1(config-if)# no shutdown
EC1(config-if)# end
EC2 — EC1 and EC2 — prepare separately on both switches
EC2# configure terminal
EC2(config)# vlan 10
EC2(config-vlan)# name SALES
EC2(config-vlan)# exit
EC2(config)# vlan 20
EC2(config-vlan)# name IT
EC2(config-vlan)# exit
EC2(config)# interface range GigabitEthernet0/1 - 2
EC2(config-if-range)# shutdown
EC2(config-if-range)# switchport mode trunk
EC2(config-if-range)# switchport trunk allowed vlan 10,20
EC2(config-if-range)# channel-group 1 mode active
EC2(config-if-range)# exit
EC2(config)# interface Port-channel1
EC2(config-if)# switchport mode trunk
EC2(config-if)# switchport trunk allowed vlan 10,20
EC2(config-if)# no shutdown
EC2(config-if)# end
EC1 — EC1 and EC2 — enable after both ends are prepared
EC1# configure terminal
EC1(config)# interface range GigabitEthernet0/1 - 2
EC1(config-if-range)# no shutdown
EC1(config-if-range)# end
EC2 — EC1 and EC2 — enable after both ends are prepared
EC2# configure terminal
EC2(config)# interface range GigabitEthernet0/1 - 2
EC2(config-if-range)# no shutdown
EC2(config-if-range)# end
EC1 — EC1 and EC2 — verify
EC1# show etherchannel summary
EC1# show lacp neighbor
EC1# show interfaces trunk
EC2 — EC1 and EC2 — verify
EC2# show etherchannel summary
EC2# show lacp neighbor
EC2# show interfaces trunk
12

12. Verification and common failures

Example: a VLAN works locally but fails across a switch link. Check VLAN membership and trunk state before changing routing.

  • show interfaces trunk: confirm the VLAN is allowed, active and forwarding across the trunk.
  • show interfaces GigabitEthernet0/1 switchport: inspect administrative and operational mode, native VLAN and allowed list.
  • show spanning-tree vlan 10: check whether STP is blocking the path.
  • show etherchannel summary: look for an operational Layer 2 bundle, commonly Po1(SU), and bundled members marked (P); read the output legend.
  • copy running-config startup-config: save each device after verification.

Same VLAN fails across switches: check the VLAN exists on both ends and is permitted on the trunk.

Same VLAN works, inter-VLAN fails: check host gateways, router subinterface VLAN tags or SVI state and ip routing on the Layer 3 switch.

EtherChannel suspended or individual: compare member settings, LACP mode and peer cabling. Do not treat a configured Port-channel as proof of an operational bundle.

Native-VLAN mismatch: align both ends of the specific link. Err-disabled PC port: investigate BPDU Guard before re-enabling it.

R1 — Each configured device — save the verified lab
R1# copy running-config startup-config
SW1 — Each configured device — save the verified lab
SW1# copy running-config startup-config
SW2 — Each configured device — save the verified lab
SW2# copy running-config startup-config
MLS1 — Each configured device — save the verified lab
MLS1# copy running-config startup-config
R2 — Each configured device — save the verified lab
R2# copy running-config startup-config
EC1 — Each configured device — save the verified lab
EC1# copy running-config startup-config
EC2 — Each configured device — save the verified lab
EC2# copy running-config startup-config
13

13. Cisco references

Cisco — Configure Inter VLAN Routing with an External Router:
https://www.cisco.com/c/en/us/support/docs/lan-switching/inter-vlan-routing/14976-50.html

Cisco — EtherChannel Configuration Guide:
https://www.cisco.com/c/en/us/td/docs/switches/lan/c9000/lyr2-fwd/etherchannel/etherchannel-configuration-guide/etherchannels.html

Cisco — Spanning Tree configuration model:
https://netascode.cisco.com/docs/data_models/iosxe/device/spanning_tree/