NET · Guide · CCNA 200-301

The 50 most important CCNA switching commands

A practical guide to the 50 Cisco IOS commands you need to configure, secure and troubleshoot switches for the CCNA 200-301: IOS, MAC address table, STP, RSTP, security, show and debug commands.

Cisco Catalyst 4506-E switch with its 48-port line cards and power supplies
Wikimedia Commons · X-Javier · CC BY-SA 4.0

On the CCNA 200-301 exam and in your first job as a network engineer, the switch is the device you'll configure most. This guide brings together the 50 Cisco IOS commands I use and teach every day to manage switches: from first access all the way to port security and troubleshooting with show and debug.

Each command shows the IOS mode where you type it (the prompt) and what it's for. At the end of each section you'll find an example ready to practice in Packet Tracer or in your lab.

Mode: SW1> user EXEC · SW1# privileged EXEC · SW1(config)# global configuration · SW1(config-if)# interface · SW1(config-line)# line · SW1(config-vlan)# VLAN.

Download the PDF guide. The same guide, ready to print or keep handy in the lab.

Download the PDF guide

Managing IOS on the switch

The first things you do with a new switch: give it a name, protect access, enable remote management over SSH, and get the VLANs and ports ready.

#CommandWhat it's for
1SW1>enableEnters privileged EXEC mode, where you can see and change everything.
2SW1#configure terminalEnters global configuration mode.
3SW1(config)#hostname SW1Sets the switch name; it shows up in the prompt and in the logs.
4SW1(config)#enable secret Cl4v3$eguraProtects privileged mode with a hashed password.
5SW1(config)#service password-encryptionEncrypts the passwords that appear in plain text in the configuration.
6SW1(config)#banner motd # Authorized personnel only #Displays a legal notice to anyone who connects to the device.
7SW1(config-line)#line console 0
password
login
logging synchronous
Protects the console port and keeps log messages from interrupting what you type.
8SW1(config)#ip domain-name thor.lab
crypto key generate rsa modulus 2048
Generates the RSA keys SSH needs (requires a hostname and a domain name).
9SW1(config)#username admin secret Cl4v3$eguraCreates a local user to log in over SSH.
10SW1(config-line)#line vty 0 15
transport input ssh
login local
Allows remote management over SSH only, using local users.
11SW1(config-if)#interface vlan 1
ip address 192.168.1.2 255.255.255.0
no shutdown
Configures the switch virtual interface (SVI) with the switch's management IP.
12SW1(config)#ip default-gateway 192.168.1.1Sets the default gateway so you can manage the switch from other networks.
13SW1(config-vlan)#vlan 10
name SALES
Creates a VLAN and gives it a name.
14SW1(config-if)#switchport mode access
switchport access vlan 10
Makes the port an access port and assigns it to a VLAN.
15SW1(config-if)#switchport mode trunk
switchport trunk allowed vlan 10,20
Makes the port an 802.1Q trunk and limits which VLANs are carried over it.
16SW1#copy running-config startup-configSaves the configuration so it survives a reload.
SW1# configure terminal
SW1(config)# hostname SW1
SW1(config)# ip domain-name thor.lab
SW1(config)# username admin secret Cl4v3$egura
SW1(config)# crypto key generate rsa modulus 2048
SW1(config)# line vty 0 15
SW1(config-line)# transport input ssh
SW1(config-line)# login local
SW1(config-line)# end
SW1# copy running-config startup-config

Managing the MAC address table

The switch learns the MAC addresses of connected devices and maps each one to a port and a VLAN. These commands let you view, clear and tune that table.

#CommandWhat it's for
17SW1#show mac address-tableShows every learned MAC address, with its VLAN and port.
18SW1#show mac address-table dynamic interface g0/1Filters the MAC addresses learned on a specific port.
19SW1#clear mac address-table dynamicClears the dynamic entries so the switch learns them again.
20SW1(config)#mac address-table aging-time 300Changes how many seconds a MAC address is kept without traffic (300 by default).
21SW1(config)#mac address-table static 0011.2233.4455 vlan 10 interface g0/5Permanently binds a MAC address to a port.
SW1# show mac address-table dynamic vlan 10
          Mac Address Table
-------------------------------------------
Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
  10    0011.2233.4455    DYNAMIC     Gi0/5
  10    00aa.bbcc.ddee    DYNAMIC     Gi0/1

Managing STP

Spanning Tree prevents Layer 2 loops by blocking redundant paths. On Cisco, PVST+ builds one tree per VLAN.

#CommandWhat it's for
22SW1(config)#spanning-tree mode pvstEnables PVST+, an independent spanning tree for each VLAN.
23SW1(config)#spanning-tree vlan 10 root primaryMakes the switch the root bridge for the VLAN by adjusting its priority.
24SW1(config)#spanning-tree vlan 10 priority 4096Sets the bridge priority manually (multiples of 4096; the lowest wins).
25SW1(config-if)#spanning-tree vlan 10 cost 19Changes the port cost to influence which path stays active.
26SW1(config-if)#spanning-tree vlan 10 port-priority 64Breaks ties between ports with the same cost to the root.
27SW1(config-if)#spanning-tree portfastMoves an access port straight to forwarding without waiting for STP.
28SW1(config-if)#spanning-tree bpduguard enableShuts the port down (err-disabled) if it receives a BPDU, protecting the topology.
SW1(config)# spanning-tree vlan 10 root primary
SW1(config)# interface range g0/1 - 20
SW1(config-if-range)# spanning-tree portfast
SW1(config-if-range)# spanning-tree bpduguard enable
Cisco Nexus 7700 data center switch chassis
Data center Nexus switches also run Spanning Tree on their access ports. Photo: Patrick Finnegan, Wikimedia Commons (CC BY 2.0).

Managing RSTP

Rapid Spanning Tree (802.1w) converges in seconds instead of the 30 to 50 seconds of classic STP. On Cisco you use Rapid PVST+.

#CommandWhat it's for
29SW1(config)#spanning-tree mode rapid-pvstEnables Rapid PVST+, the fast, per-VLAN version of RSTP.
30SW1(config-if)#spanning-tree link-type point-to-pointDeclares a point-to-point (full-duplex) link so it converges using the proposal/agreement mechanism.
31SW1(config-if)#spanning-tree portfast edgeMarks an edge port facing end devices on IOS 15.2 or later.
32SW1(config-if)#spanning-tree guard rootPrevents a switch connected to that port from becoming the root bridge.
33SW1(config)#spanning-tree loopguard defaultPrevents loops if a port stops receiving BPDUs because of a unidirectional link failure.
SW1(config)# spanning-tree mode rapid-pvst
SW1(config)# interface g0/24
SW1(config-if)# spanning-tree link-type point-to-point
SW1(config-if)# spanning-tree guard root

Managing security

Access ports are the front door to your network. These commands limit who can connect and block the most common Layer 2 attacks.

#CommandWhat it's for
34SW1(config-if)#switchport port-securityEnables port security (the port must be in access mode).
35SW1(config-if)#switchport port-security maximum 2Limits how many MAC addresses can use the port.
36SW1(config-if)#switchport port-security mac-address stickyLearns the allowed MAC addresses and saves them to the configuration.
37SW1(config-if)#switchport port-security violation restrictDrops and logs unauthorized traffic without shutting the port down (protect, restrict or shutdown).
38SW1(config)#errdisable recovery cause psecure-violationAutomatically re-enables, after a timer, only the ports shut down by a security violation.
39SW1(config)#ip dhcp snooping
ip dhcp snooping vlan 10
Blocks rogue DHCP servers on the specified VLANs.
40SW1(config-if)#ip dhcp snooping trustMarks the port toward the legitimate DHCP server, or the trunk, as trusted.
41SW1(config)#ip arp inspection vlan 10Enables Dynamic ARP Inspection (DAI) against ARP poisoning.
SW1(config)# interface g0/5
SW1(config-if)# switchport mode access
SW1(config-if)# switchport port-security
SW1(config-if)# switchport port-security maximum 2
SW1(config-if)# switchport port-security mac-address sticky
SW1(config-if)# switchport port-security violation restrict

show commands

With show you verify without changing anything. They're your best allies on the exam and in real-world troubleshooting.

#CommandWhat it's for
42SW1#show versionIOS version, model, memory, uptime and configuration register.
43SW1#show running-configThe active configuration in RAM.
44SW1#show interfaces statusStatus, VLAN, duplex and speed of every port in a single table.
45SW1#show vlan briefThe VLANs you've created and the access ports assigned to each one.
46SW1#show interfaces trunkThe trunks, their native VLAN, and the allowed and active VLANs.
47SW1#show spanning-tree vlan 10The root bridge, plus the role and state of every port in that VLAN.
48SW1#show port-security interface g0/5The port security settings and the violation counter.
SW1# show interfaces trunk
Port      Mode   Encapsulation  Status    Native vlan
Gi0/24    on     802.1q         trunking  1

Port      Vlans allowed on trunk
Gi0/24    10,20
Engineer in front of several screens showing logs and configurations
The answer is almost always in the output of a show command; you just have to know how to read it. Photo: Esten Erbol on Unsplash.

debug commands

debug shows events in real time. Use it carefully in production: it eats CPU and can generate a lot of output.

#CommandWhat it's for
49SW1#terminal monitor
debug spanning-tree events
Shows STP topology and state changes in an SSH session.
50SW1#undebug allTurns off all debugging immediately; always keep it handy.
SW1# terminal monitor
SW1# debug spanning-tree events
Spanning Tree event debugging is on
...
SW1# undebug all
All possible debugging has been turned off

What you take away

  • Secure access from day one: enable secret, SSH and local login.
  • Master the MAC address table: it's the fastest way to find where a device is connected.
  • Control which switch is the STP root bridge and protect access ports with PortFast and BPDU Guard.
  • Always verify with show, and use debug only for as long as you need it.

Practice each section in Packet Tracer until you can type the commands without looking at the guide.

Get ready for the CCNA with us

In The House of Routing's Networking path, you prepare for the CCNA 200-301 with theory, Packet Tracer labs and chapter challenges. Start for free today.

Download the free mini guide “The 100 most important CCNA 200-301 v1.1 commands” as a PDF. Switching, VLANs, STP, OSPF, IPv6, security, services and troubleshooting, with the IOS mode of every command. Ready to print and keep next to you while you practice.

Download the free PDF

Explore the Networking path

Sources

Photos: Cisco Catalyst 4506-E by X-Javier (CC BY-SA 4.0) and Cisco Nexus 7700 by Patrick Finnegan (CC BY 2.0), on Wikimedia Commons; console photo by Esten Erbol on Unsplash. Text by Jesús Espinoza, prepared with AI assistance and reviewed by him.

↑ Start of the article