Lab 6 — Port Security
One switch, two PCs, and a rogue laptop.
Shut down what isn’t used, lock each port to the MACs it should see, and watch the switch drop — or shut down on — the device that doesn’t belong. Work through it in order — check steps off, copy the commands, and finish with the show commands that prove what was learned.
Interactive lab — play with it
A simulated CLI for this lab. Click the switch or a PC, type the commands, and generate real traffic: the PCs’ pings teach the switch their MACs, and the rogue laptop’s pings trip the violations.
A simulated CLI for this lab — click the switch or a PC, type the commands, and generate real traffic: the PCs’ pings are what teach the switch their MACs, and the rogue laptop’s pings are what trip the violations. This models Lab 6’s commands only, not a real switch: unsupported commands say so instead of faking it. Type ? for help and use Tab to complete a command.
Microsoft Windows [Version 10.0.19045.0]
(c) Microsoft Corporation. All rights reserved.
Up/down arrows recall commands. The full command list is in the walkthrough below.
Interactive lab
Lab 6 — Port Security
One switch, two PCs, and a rogue laptop. Shut down what isn’t used, lock each port to the MACs it should see, and watch the switch drop — or shut down on — the device that doesn’t belong.
Click a device to open its console, type the real commands, and check your work when you think it’s done. The lab checks each step as you go.
Walkthrough — commands in order
One switch, two PCs, and a rogue laptop. Shut down what isn’t used, lock each port to the MACs it should see, and watch the switch drop — or shut down on — the device that doesn’t belong.
PC1 (0000.1111.1111) ── Fa0/1 [SW1] Fa0/2 ── PC2 (0000.2222.2222)
Rogue laptop (0000.3333.3333) ── Fa0/2 jack (PC2 unplugged)
Unused ports Fa0/3-4, Gi0/1-2 — shut downWhere this shows up in the data center
In the data center I don’t configure port security on top-of-rack host ports — that’s the access layer’s job — but the posture is the same one guarding every management interface I touch: only known devices on the wire, unknown ones shut out. It’s the same thinking as the access controls on ILOM and the firewall rules on OPNsense at home: deny by default, permit explicitly, and make the violation visible.
SW1(config)# interface range f0/3 - 4 SW1(config-if-range)# shutdown SW1(config)# interface range g0/1 - 2 SW1(config-if-range)# shutdown
SW1(config)# interface f0/1 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 0000.1111.1111
SW1(config)# interface f0/2 SW1(config-if)# switchport mode access SW1(config-if)# switchport port-security
C:\> ping 192.168.1.12
Run this from PC1. PC2’s MAC (0000.2222.2222) is learned on Fa0/2 when its reply comes back.
SW1# show port-security SW1# show port-security interface f0/1 SW1# show port-security interface f0/2
SW1(config)# interface f0/2 SW1(config-if)# switchport port-security violation restrict C:\> ping 192.168.1.11
Run the ping from the rogue laptop. It times out; the violation count on Fa0/2 goes to 1.
SW1(config)# interface f0/2 SW1(config-if)# switchport port-security violation shutdown C:\> ping 192.168.1.11 SW1(config)# interface f0/2 SW1(config-if)# shutdown SW1(config-if)# no shutdown
Run the ping from the rogue laptop again — Fa0/2 goes err-disabled. The shutdown / no shutdown pair brings it back to Secure-up.
Verify it worked
Don’t trust the config until a show command proves it. These are the outputs you should see — if yours differ, that’s the troubleshooting.
SW1# show port-security
Secure Port MaxSecureAddr CurrentAddr SecurityViolation Security Action
(Count) (Count) (Count)
---------------------------------------------------------------------------
Fa0/1 2 1 0 Shutdown
Fa0/2 1 1 0 Shutdown
---------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port) : 2
Max Addresses limit in System (excluding one mac per port) : 8192SW1# show port-security interface f0/1
Port Security : Enabled Port Status : Secure-up Violation Mode : Shutdown Aging Time : 0 mins Aging Type : Absolute SecureStatic Address Aging : Disabled Maximum MAC Addresses : 2 Total MAC Addresses : 1 Configured MAC Addresses : 1 Sticky MAC Addresses : 0 Last Source Address:Vlan : 0000.1111.1111:1 Security Violation Count : 0
SW1# show port-security interface f0/2
Port Security : Enabled Port Status : Secure-up Violation Mode : Shutdown Aging Time : 0 mins Aging Type : Absolute SecureStatic Address Aging : Disabled Maximum MAC Addresses : 1 Total MAC Addresses : 1 Configured MAC Addresses : 0 Sticky MAC Addresses : 0 Last Source Address:Vlan : 0000.2222.2222:1 Security Violation Count : 0
SW1# show port-security address
Secure Mac Address Table
-----------------------------------------------------------------------------
Vlan Mac Address Type Ports Remaining Age
(mins)
---- ----------- ---- ----- -------------
1 0000.1111.1111 SecureConfigured Fa0/1 -
1 0000.2222.2222 SecureDynamic Fa0/2 -
-----------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port) : 2
Max Addresses limit in System (excluding one mac per port) : 8192Check yourself
Three questions from the exam angle. Tap to reveal the answer — say it out loud first.
Q1. What does each violation mode do — and which one counts the violation?
Q2. Why must the port be in access mode before port security will turn on?
Q3. Fa0/1 allows 2 MACs with PC1’s written in. A second device plugs in and works — a third is dropped. Why?
Next labs:
Keep going: Lab 7 — DHCP hands out addresses on the VLANs you just secured, or revisit Lab 4 — Inter-VLAN Routing or Lab 5 — EtherChannel. All labs are on the labs hub.