LAB: Layer 2 Security
A switch that trusts every plugged-in device is a switch that lets strangers in the door. In this lab you turn port security on an access port with sticky MAC learning, trigger a violation, and recover the port from err-disable — then you enable DHCP snooping and watch a client’s lease get recorded in the binding table. These are the exact features that appear on the CCNA security labs.
- Configure port security with a MAC maximum and sticky learning.
- Trigger each violation mode and observe the difference.
- Recover a port from the err-disabled state, manually and automatically.
- Enable DHCP snooping globally and per-VLAN, with a trusted uplink.
- Verify with show port-security, show interface status, and show ip dhcp snooping binding.
- Relate each feature it to the attack it stops (rogue device, rogue DHCP server).
Overview and goal
A single switch builds a small LAN. On the user port (Fa0/1) you will enforce one allowed MAC address, learned sticky, and watch a second device trip the violation — first in restrict mode, then with the default shutdown, so you see the err-disable state and its recovery. Then you will add DHCP snooping: the client (or a router acting as the DHCP server on the port you trust) does a normal DORA exchange, and you inspect the resulting binding table. Along the way you practise the verification commands that every Layer 2 security question assumes.
shutdown-mode violation.
DHCP snooping validates DHCP offers/acks against trusted ports and builds a binding table.Topology
Setup and addressing
| Device | Port | Role | IP / notes |
|---|---|---|---|
| S1 | Fa0/1 | User access port | Port security + sticky |
| S1 | Fa0/2 | Spare port | Used to test violation behaviour |
| S1 | Gi0/1 | Uplink / DHCP server | Trusted for DHCP snooping |
| PC1 | — | DHCP client | 192.168.10.50 (from server) |
| DHCP Server | — | Address server | 192.168.10.10, pool 192.168.10.0/24 |
On an 2960-class switch, this shape works out of the box: the defaults are
switchport port-security maximum 1 and violation mode shutdown.
Step 1 — Port security with sticky MAC
Configure the access port with port security, cap it at one address, and let it learn PC1’s MAC as a sticky entry:
S1(config)# interface fastethernet0/1 S1(config-if)# switchport mode access S1(config-if)# switchport port-security S1(config-if)# switchport port-security maximum 1 S1(config-if)# switchport port-security mac-address sticky S1(config-if)# switchport port-security violation shutdown S1(config-if)# end S1# show port-security interface fastethernet0/1 Port Security : Enabled Port Status : Secure-up Violation Mode : Shutdown Maximum MAC Addresses : 1 Total MAC Addresses : 1 Configured MAC Addresses : 0 Sticky MAC Addresses : 1 Last Source Address:Vlan : 0050.7966.6800:10
mac-address 0050.7966.6800) is precise but fragile — every
legitimate hardware swap needs a config edit. Sticky records whatever device is plugged in at the time,
so setup is one command and the address lands in the running config. Remember to
copy running-config startup-config or the sticky entry evaporates on reboot.
Step 2 — Trigger a violation
Now unplug PC1, plug a different device (PC2) into Fa0/1, and generate traffic. Because PC2’s MAC is not the learned one and the maximum is 1, a violation fires. With violation mode shutdown, the interface goes err-disabled:
S1# show interfaces status Port Name Status Vlan Duplex Speed Type Fa0/1 err-disabled 10 auto auto ...
shutdown mode puts the port into err-disable (shown as err-disabled) and
blocks all traffic — not just the rogue MAC. The lighter modes restrict
(drops + logs + counter) and protect (silently drops) leave the port up. The exam will
hand you one of the three symptoms and ask you to name the mode.
Experiment worth doing in the simulator: repeat with violation restrict to watch the
SecurityViolation counter rise while the port stays up, and protect to see the silent drop.
You will never forget the three after you have seen each happen.
Step 3 — Recover from err-disable
err-disabled ports do not self-heal by default. Recovery is either manual — bounce the port — or automatic, after a timer, using the specific err-disable cause:
! Manual recovery (works immediately) S1(config)# interface fastethernet0/1 S1(config-if)# shutdown S1(config-if)# no shutdown S1(config-if)# exit ! Or automatic recovery for port-security violations S1(config)# errdisable recovery cause psecure-violation S1(config)# errdisable recovery interval 300 S1(config)# end S1# show errdisable detect | include psecure
Step 4 — DHCP snooping
DHCP snooping makes the switch distrust client ports for DHCP offers/acks. Enable it globally and for VLAN 10, then mark the uplink to the real DHCP server as trusted:
S1(config)# ip dhcp snooping S1(config)# ip dhcp snooping vlan 10 S1(config)# interface gigabitethernet0/1 S1(config-if)# ip dhcp snooping trust S1(config-if)# exit S1(config)# interface fastethernet0/1 S1(config-if)# ip dhcp snooping limit rate 10 S1(config-if)# end
Only the port facing the server is trusted now. Every untrusted port (Fa0/1, Fa0/2 …)
can send DHCP discover/request, but any DHCP offer or ack arriving from
it is dropped — which is precisely how a rogue DHCP server on the desk is neutralised.
ip dhcp snooping limit rate 10 caps the DHCP message rate to stop a flood of requests from
saturating the CPU.
Step 5 — Verify the binding and filtering
Restart the client interface (or renew its lease) so a fresh DORA exchange happens, then inspect the results:
S1# show ip dhcp snooping Switch DHCP snooping is enabled DHCP snooping is configured on following VLANs: 10 Insertion of option 82 is enabled Interface Trusted Rate limit (pps) ----------------------------- ---------- ---------------- GigabitEthernet0/1 yes unlimited FastEthernet0/1 no 10 S1# show ip dhcp snooping binding MacAddress IpAddress Lease(sec) Type VLAN Interface ------------------ --------------- ---------- ------------- ---- ----------------- 00:50:79:66:68:00 192.168.10.50 86215 dhcp-snooping 10 FastEthernet0/1 S1# show port-security address Secure Mac Address Table Vlan Mac Address Type Ports ---- --------------- ----------- ----- 10 0050.7966.6800 SecureSticky Fa0/1
Two proofs in one screen: the DHCP binding table links PC1’s MAC to its leased IP on Fa0/1
— ready to be consumed by DAI in a larger design — and the port-security table shows the
sticky MAC with type SecureSticky.
Troubleshooting guide
- Port shows err-disabled after plugging in a device: port security in
shutdownmode. Verify withshow interfaces status; recover withshutdown/no shutdown. - Sticky MAC disappeared: it was never saved.
copy running-config startup-config. - Client gets no address: check
show ip dhcp snoopingfor the trusted port. A wrongly marked port blocks legitimate DHCP packets. - Port security does nothing: you applied it on a trunk or
dynamic port. Port security requires
switchport mode access. - Violation keeps recurring: the rogue device is still attached (or the ethics of a colleague’s newly-joined laptop on the desk have caught up with you). Find and remove it.
The vocabulary you need
Every term below appears in the lesson text above. Select one to read its definition, then use the quiz at the end to check what stuck.
Review
Check what you have learned with these review questions.
Sources & references
- Cisco. CCNA (200-301) Exam Topics. cisco.com.
- IETF. Request for Comments (RFCs). rfc-editor.org.
- IANA. Internet Assigned Numbers Authority registries. iana.org.
Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.