Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityIntermediate

Cisco switch commands: VLANs, trunks and port security

In short: A quick reference of the Cisco IOS commands used to build and secure an access switch. Commands only.

Commands only. Replace values in angle brackets such as <ip> with your own. Only run commands on systems you own or are authorised to manage.

Basic setup and secure management

enable
configure terminal
hostname SW1
enable secret <strong-secret>
service password-encryption
banner motd #Authorised access only#
no ip domain-lookup
username admin privilege 15 secret <strong-secret>
ip domain-name <domain>
crypto key generate rsa modulus 2048
ip ssh version 2
line console 0
 login local
 exec-timeout 5 0
line vty 0 15
 login local
 transport input ssh
 exec-timeout 5 0
interface vlan 99
 ip address <ip> <mask>
 no shutdown
ip default-gateway <gateway-ip>
end
copy running-config startup-config

VLANs and access ports

vlan 10
 name STAFF
vlan 20
 name VOICE
vlan 99
 name MGMT
interface range fastEthernet 0/1 - 12
 switchport mode access
 switchport access vlan 10
 switchport voice vlan 20
 switchport nonegotiate
 spanning-tree portfast
 spanning-tree bpduguard enable

Trunks

interface gigabitEthernet 0/1
 switchport mode trunk
 switchport trunk native vlan 999
 switchport trunk allowed vlan 10,20,99
 switchport nonegotiate

Port security and unused ports

interface fastEthernet 0/5
 switchport mode access
 switchport port-security
 switchport port-security maximum 2
 switchport port-security mac-address sticky
 switchport port-security violation restrict
interface range fastEthernet 0/13 - 24
 switchport mode access
 switchport access vlan 999
 shutdown

DHCP snooping and dynamic ARP inspection

ip dhcp snooping
ip dhcp snooping vlan 10,20
no ip dhcp snooping information option
interface gigabitEthernet 0/1
 ip dhcp snooping trust
 ip arp inspection trust
interface range fastEthernet 0/1 - 12
 ip dhcp snooping limit rate 10
ip arp inspection vlan 10,20

Verification commands

CommandPurpose
show running-configCurrent configuration
show vlan briefVLANs and their access ports
show interfaces trunkTrunk ports, native and allowed VLANs
show interfaces statusPort status, VLAN, speed and duplex
show mac address-tableLearned MAC addresses per port
show port-security interface <int>Port security state and violation count
show ip dhcp snooping bindingDHCP snooping binding table
show ip arp inspection vlan <id>DAI status for a VLAN
show spanning-treeSTP root, roles and states
show ip sshSSH version and status
errdisable recovery cause psecure-violationAuto-recover ports shut by port security

Real-world example: a rogue DHCP server in a college lab

Building an access switchSecure managementSSH, users, bannerVLANscreate and nameAccess portsone VLAN eachTrunksuplinks, allowed VLANsPort protectionport security, BPDU GuardDHCP snooping, DAIstop rogue servers
Figure 1. The order in which the commands on this page are usually applied when building a new access switch, from basic management to protection features.

In a further education college, students in one computer lab suddenly lost internet access. Their PCs had addresses in 192.168.0.0/24 instead of the lab's 10.20.30.0/24 range. A student had plugged in a home router to get extra ports, and its built-in DHCP server was answering faster than the college's real server.

The network technician found the router's port with show mac address-table, shut it down and removed the device. To stop it happening again she enabled DHCP snooping on the lab VLAN, marked only the uplink to the core as trusted, and added PortFast with BPDU Guard and port security on every student port. When the same thing was tried a term later, the rogue DHCP offers were dropped and the lab carried on working.

Key takeaways

  • Manage switches only over SSH with local or AAA accounts.
  • Set access ports explicitly, disable DTP and enable PortFast with BPDU guard.
  • Use an unused native VLAN and restrict allowed VLANs on trunks.
  • Shut unused ports and apply port security, DHCP snooping and DAI.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.