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.
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.
| # | Command | What it's for |
|---|---|---|
| 1 | SW1>enable | Enters privileged EXEC mode, where you can see and change everything. |
| 2 | SW1#configure terminal | Enters global configuration mode. |
| 3 | SW1(config)#hostname SW1 | Sets the switch name; it shows up in the prompt and in the logs. |
| 4 | SW1(config)#enable secret Cl4v3$egura | Protects privileged mode with a hashed password. |
| 5 | SW1(config)#service password-encryption | Encrypts the passwords that appear in plain text in the configuration. |
| 6 | SW1(config)#banner motd # Authorized personnel only # | Displays a legal notice to anyone who connects to the device. |
| 7 | SW1(config-line)#line console 0passwordloginlogging synchronous | Protects the console port and keeps log messages from interrupting what you type. |
| 8 | SW1(config)#ip domain-name thor.labcrypto key generate rsa modulus 2048 | Generates the RSA keys SSH needs (requires a hostname and a domain name). |
| 9 | SW1(config)#username admin secret Cl4v3$egura | Creates a local user to log in over SSH. |
| 10 | SW1(config-line)#line vty 0 15transport input sshlogin local | Allows remote management over SSH only, using local users. |
| 11 | SW1(config-if)#interface vlan 1ip address 192.168.1.2 255.255.255.0no shutdown | Configures the switch virtual interface (SVI) with the switch's management IP. |
| 12 | SW1(config)#ip default-gateway 192.168.1.1 | Sets the default gateway so you can manage the switch from other networks. |
| 13 | SW1(config-vlan)#vlan 10name SALES | Creates a VLAN and gives it a name. |
| 14 | SW1(config-if)#switchport mode accessswitchport access vlan 10 | Makes the port an access port and assigns it to a VLAN. |
| 15 | SW1(config-if)#switchport mode trunkswitchport trunk allowed vlan 10,20 | Makes the port an 802.1Q trunk and limits which VLANs are carried over it. |
| 16 | SW1#copy running-config startup-config | Saves 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.
| # | Command | What it's for |
|---|---|---|
| 17 | SW1#show mac address-table | Shows every learned MAC address, with its VLAN and port. |
| 18 | SW1#show mac address-table dynamic interface g0/1 | Filters the MAC addresses learned on a specific port. |
| 19 | SW1#clear mac address-table dynamic | Clears the dynamic entries so the switch learns them again. |
| 20 | SW1(config)#mac address-table aging-time 300 | Changes how many seconds a MAC address is kept without traffic (300 by default). |
| 21 | SW1(config)#mac address-table static 0011.2233.4455 vlan 10 interface g0/5 | Permanently 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.
| # | Command | What it's for |
|---|---|---|
| 22 | SW1(config)#spanning-tree mode pvst | Enables PVST+, an independent spanning tree for each VLAN. |
| 23 | SW1(config)#spanning-tree vlan 10 root primary | Makes the switch the root bridge for the VLAN by adjusting its priority. |
| 24 | SW1(config)#spanning-tree vlan 10 priority 4096 | Sets the bridge priority manually (multiples of 4096; the lowest wins). |
| 25 | SW1(config-if)#spanning-tree vlan 10 cost 19 | Changes the port cost to influence which path stays active. |
| 26 | SW1(config-if)#spanning-tree vlan 10 port-priority 64 | Breaks ties between ports with the same cost to the root. |
| 27 | SW1(config-if)#spanning-tree portfast | Moves an access port straight to forwarding without waiting for STP. |
| 28 | SW1(config-if)#spanning-tree bpduguard enable | Shuts 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
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+.
| # | Command | What it's for |
|---|---|---|
| 29 | SW1(config)#spanning-tree mode rapid-pvst | Enables Rapid PVST+, the fast, per-VLAN version of RSTP. |
| 30 | SW1(config-if)#spanning-tree link-type point-to-point | Declares a point-to-point (full-duplex) link so it converges using the proposal/agreement mechanism. |
| 31 | SW1(config-if)#spanning-tree portfast edge | Marks an edge port facing end devices on IOS 15.2 or later. |
| 32 | SW1(config-if)#spanning-tree guard root | Prevents a switch connected to that port from becoming the root bridge. |
| 33 | SW1(config)#spanning-tree loopguard default | Prevents 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.
| # | Command | What it's for |
|---|---|---|
| 34 | SW1(config-if)#switchport port-security | Enables port security (the port must be in access mode). |
| 35 | SW1(config-if)#switchport port-security maximum 2 | Limits how many MAC addresses can use the port. |
| 36 | SW1(config-if)#switchport port-security mac-address sticky | Learns the allowed MAC addresses and saves them to the configuration. |
| 37 | SW1(config-if)#switchport port-security violation restrict | Drops and logs unauthorized traffic without shutting the port down (protect, restrict or shutdown). |
| 38 | SW1(config)#errdisable recovery cause psecure-violation | Automatically re-enables, after a timer, only the ports shut down by a security violation. |
| 39 | SW1(config)#ip dhcp snoopingip dhcp snooping vlan 10 | Blocks rogue DHCP servers on the specified VLANs. |
| 40 | SW1(config-if)#ip dhcp snooping trust | Marks the port toward the legitimate DHCP server, or the trunk, as trusted. |
| 41 | SW1(config)#ip arp inspection vlan 10 | Enables 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.
| # | Command | What it's for |
|---|---|---|
| 42 | SW1#show version | IOS version, model, memory, uptime and configuration register. |
| 43 | SW1#show running-config | The active configuration in RAM. |
| 44 | SW1#show interfaces status | Status, VLAN, duplex and speed of every port in a single table. |
| 45 | SW1#show vlan brief | The VLANs you've created and the access ports assigned to each one. |
| 46 | SW1#show interfaces trunk | The trunks, their native VLAN, and the allowed and active VLANs. |
| 47 | SW1#show spanning-tree vlan 10 | The root bridge, plus the role and state of every port in that VLAN. |
| 48 | SW1#show port-security interface g0/5 | The 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
debug commands
debug shows events in real time. Use it carefully in production: it eats CPU and can generate a lot of output.
| # | Command | What it's for |
|---|---|---|
| 49 | SW1#terminal monitordebug spanning-tree events | Shows STP topology and state changes in an SSH session. |
| 50 | SW1#undebug all | Turns 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.
Sources
- Cisco CCNA certification (200-301)cisco.com
- Understanding Rapid Spanning Tree Protocol (802.1w)cisco.com
- How to configure port security on Cisco Catalyst switchescommunity.cisco.com
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.
