Introduction
Network switches are commonly managed through command-line interfaces for monitoring ports, identifying connected devices, managing VLANs, checking port status, and reviewing system logs.
In this post, we have listed a few useful switch commands that can be used in day-to-day network administration and troubleshooting. These commands can help administrators quickly identify MAC addresses, switch ports, VLAN information, port speed, configuration status, and recent switch logs.
Prerequisites
Before executing the commands, ensure that you have:
- Access to the switch command-line interface.
- The required administrative privileges.
- Basic knowledge of switch ports and VLANs.
- The required MAC address, VLAN number, or port number, where applicable.
Implementation
1. Find the Switch Port Associated with a MAC Address
To get the switch port of a MAC address, use the following command.
# show mac address-table address xx:xx:xx:xx:xx:xx Aging time is 300 sec Vlan Mac Address Port Type ——– ——————— ———- ———- 100 xx:xx:xx:xx:xx:xx gi1/0/12 dynamic
This command can be used to identify the switch port associated with a specific MAC address.
2. View the MAC Address of a Switch Port
To view the MAC address associated with a switch port, execute the following command.
# show mac address-table interface gi1/0/2 Aging time is 300 sec Vlan Mac Address Port Type ——– ——————— ———- ———- 100 xx:xx:xx:xx:xx:xx gi1/0/2 dynamic
3. View the VLAN and Administrative Mode of a Switch Port
To view the VLAN and administrative mode of a switch port, execute the following command.
#show interfaces switchport gi1/0/12 …….. Administrative Mode: access Access Mode VLAN: 100
4. Check the Speed of a Switch Port
To get the speed of a switch port, use the following command.
# show interfaces status gi1/0/12 Flow Link Back Mdix Port Type Duplex Speed Neg ctrl State Pressure Mode ——– ———— —— —– ——– —- ———– ——– ——- gi1/0/12 1G-Copper Full 100 Enabled On Up Disabled Off
5. Change the VLAN of a Switch Port
To change the VLAN of a switch port, follow the steps below.
#configure (config)#interface gi1/0/<port number> (config-if)#switchport access vlan 100
6. Configure a Switch Port for Trunking
To trunk a switch port to different VLANs, execute the following commands.
#configure (config)#interface gi1/0/<port number> (config-if)#switchport mode trunk (config-if)#switchport trunk allowed vlan add <vlan number1> <vlan number2> (config-if)#end
7. Shut Down a Single Switch Port
To shut down a single port, execute the following commands.
#configure (config)#interface gi1/0/<port number> (config-if)# shutdown
8. Copy the Running Configuration to the Startup Configuration
To copy the running configuration to the startup configuration, execute the following command.
#copy running-config startup-config
9. Add a New VLAN to the Database
To add a new VLAN to the database, follow the steps below.
#configure #vlan database # vlan <vlan number>
10. View All Switch Ports Belonging to a Particular VLAN
To view all the switch ports that belong to a particular VLAN, execute the following command.
show vlan tag <vlan number>
This will list all the switch ports that belong to the specified VLAN.
11. View Recent Switch Logs
To view the recent logs on the switch, execute the following command.
show logging
Conclusion
Switch command-line tools provide a quick and practical way to monitor and manage network infrastructure. The commands covered in this article can be used for common day-to-day tasks such as identifying connected devices, checking switch ports, managing VLANs, configuring trunk ports, saving configurations, and reviewing switch logs.
Keeping these commonly used commands available as a quick reference can help network administrators perform routine configuration and troubleshooting tasks more efficiently.
Frequently Asked Questions (FAQ)
1. How can I find which switch port is connected to a specific MAC address?
Use the following command:
show mac address-table address <mac-address>
This helps identify the switch port associated with the specified MAC address.
2. How can I check the VLAN assigned to a switch port?
Use the following command:
show interfaces switchport <interface>
This displays information such as the administrative mode and VLAN associated with the switch port.
3. How can I view the recent logs on a switch?
Use the following command:
show logging
This displays the recent log information available on the switch.
Related Article
How to Configure VNC (Virtual Network Computing) on CentOS
Talk to our experts
Have a technology challenge or looking for the right solution for your business? Our experienced team can help with development, cloud, DevOps, design, and other technology requirements. Get in touch with our experts.