Port Security
Cheat sheet · https://pcornel.dk/topic.php?topic=617
Answer
Port security limits which and how many MAC addresses can use a switch access port. Addresses can be static, learned dynamically or sticky (saved to config); a violation either shuts the port down (default), restricts or protects.
Remember
Do not infer service health from one command. For Port Security, distinguish configured intent, protocol/security state, installed forwarding state and the original workload result.
First checks
show port-security— secure ports, violationsshow port-security interface <interface>— max MACs, violation modeshow interfaces status err-disabled— shutdown ports
Commands
show port-security interface {{interface}}- Shows secure MAC state, maximum addresses and violation counters.
switchport mode access- Make the port a static access port.
switchport port-security- Enable port security on the interface.
switchport port-security maximum <number>- Set the maximum number of secure MAC addresses.
switchport port-security mac-address <mac>- Configure a static secure MAC address.
switchport port-security mac-address sticky- Learn secure MAC addresses dynamically and keep them in the running configuration.
switchport port-security violation protect- On violation, drop traffic from unknown addresses without logging.
switchport port-security violation restrict- On violation, drop traffic and log/count the violation.
switchport port-security violation shutdown- On violation, put the port into err-disabled state (default).
switchport port-security aging time <minutes>- Set how long secure addresses are kept.
switchport port-security aging type absolute- Remove secure addresses after the aging time, regardless of activity.
switchport port-security aging type inactivity- Remove secure addresses after they are inactive for the aging time.
show port-security- Display port security status per interface.
show port-security address- Display secure MAC addresses.
show port-security interface <interface>show interfaces status err-disabled
Verify in this order
MAC learned → count/allowed checked → violation action
Where it usually breaks
physical/link dependency → local object state → peer/control state → policy → forwarding/adjacency → end-to-end result
Port Security violation modes
| Mode | Violating frames | Counter/reporting | Port state | Operational use |
|---|---|---|---|---|
| protect | dropped | limited visibility compared with restrict | remains up | least disruptive filtering |
| restrict | dropped | violation counter/reporting on common platforms | remains up | enforce while retaining visibility |
| shutdown | dropped | violation recorded | commonly err-disabled/security shutdown | strongest/default-style enforcement on many platforms |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=617