Port Security Violation Modes – Detailed Explanation
1. What Are Port Security Violation Modes?
Port security is a Cisco switch feature that restricts which MAC addresses may communicate through a specific access port. A violation mode defines exactly what the switch does when a frame arrives from an unauthorised MAC address — one that exceeds the configured maximum or is not in the allowed list.
There are three violation modes available on Cisco IOS switches, each offering a different balance between security enforcement and operational continuity:
Unauthorised MAC frame arrives on port Fa0/1
|
v
Port Security checks MAC against allowed list
|
NOT ALLOWED -- which mode is configured?
|
+----+----+----------+
| | |
PROTECT RESTRICT SHUTDOWN
| | |
Drop Drop err-disable
Silent + Log/Trap port
Port UP Port DOWN
Related pages: Port Security Overview | Sticky MAC Addresses | MAC Address Table | MAC Addresses | PortFast & BPDU Guard | VLAN Tagging | VLANs | Standard & Extended ACLs | SNMP Traps | SNMP Overview | Syslog | show logging | show running-config | Step-by-Step: Port Security
2. When Does a Violation Occur?
A port security violation is triggered when either of these conditions is met:
- The number of unique source MAC addresses seen on the port exceeds the configured maximum (default: 1)
- A frame arrives from a MAC address that is not in the port's allowed MAC list (static or sticky)
This protects against: rogue devices being plugged in, users connecting unauthorised hubs or switches, MAC flooding attacks, and BYOD policy violations.
3. Protect Mode
In Protect mode, the switch silently drops frames from unauthorised MAC addresses. The port stays up and continues to forward traffic from allowed MAC addresses normally. No alert is generated.
| Attribute | Behaviour |
|---|---|
| Unauthorised frames | Silently dropped — no ICMP unreachable sent to source |
| Logging / syslog | None |
| SNMP trap | None |
| Port state | Remains up — allowed traffic continues unaffected |
| Violation counter | Incremented (visible in show port-security) |
Best use case: Environments where service continuity is critical and silent enforcement is acceptable — e.g., a public-facing kiosk port where you want to block unauthorised devices but cannot afford help-desk calls about ports going down.
Limitation: No visibility into violations — without logging you may not know rogue devices are being attempted. If monitoring is needed, use Restrict instead.
4. Restrict Mode
In Restrict mode, the switch drops frames from unauthorised MAC addresses (same as Protect) but also generates a syslog message and SNMP trap, and increments the violation counter. The port remains up.
| Attribute | Behaviour |
|---|---|
| Unauthorised frames | Dropped |
| Logging / syslog | Yes — %PORT_SECURITY-2-PSECURE_VIOLATION message logged |
| SNMP trap | Yes — sent to configured NMS |
| Port state | Remains up — allowed traffic continues |
| Violation counter | Incremented |
Best use case: General user access ports where you need visibility into violations but cannot afford port disruption — e.g., open-plan offices or labs where temporary device connections are common but should be monitored.
5. Shutdown Mode (Default)
In Shutdown mode (the Cisco IOS default), a single violation immediately places the port into an error-disabled (err-disabled) state. The port is completely shut down — no traffic passes until an administrator manually recovers it or automatic recovery is configured.
| Attribute | Behaviour |
|---|---|
| Unauthorised frames | One violation → port immediately shut down |
| Logging / syslog | Yes — violation logged with the offending MAC address |
| SNMP trap | Yes — sent to configured NMS |
| Port state | err-disabled — interface is down, all traffic stops |
| Recovery | Manual (shutdown / no shutdown) or automatic (errdisable recovery) |
Best use case: High-security environments where any unauthorised access attempt should halt connectivity immediately and trigger an investigation — server rooms, finance terminals, executive workstations, DMZ ports.
6. Comparison of All Three Modes
| Feature | Protect | Restrict | Shutdown |
|---|---|---|---|
| Unauthorised frames dropped | Yes | Yes | Yes |
| Syslog message generated | No | Yes | Yes |
| SNMP trap sent | No | Yes | Yes |
| Port remains up | Yes | Yes | No (err-disabled) |
| Violation counter increments | Yes | Yes | Yes (then port shuts) |
| Is the default mode? | No | No | Yes |
| Requires recovery action | No | No | Yes |
7. Full Configuration Example
! Step 1: Configure the port as an access port
Switch(config)# interface FastEthernet0/1
Switch(config-if)# switchport mode access
! Step 2: Enable port security
Switch(config-if)# switchport port-security
! Step 3: Set maximum allowed MAC addresses (default is 1)
Switch(config-if)# switchport port-security maximum 2
! Step 4: Set the violation mode (protect / restrict / shutdown)
Switch(config-if)# switchport port-security violation restrict
! Step 5: Enable sticky MAC (learns current MACs and saves to config)
Switch(config-if)# switchport port-security mac-address sticky
! Step 6: Verify
Switch# show port-security interface FastEthernet0/1
Switch# show port-security address
Sticky MAC: The sticky keyword makes the switch dynamically learn the first MAC address(es) seen on the port and automatically add them to the running configuration as secure MACs. This eliminates the need to manually specify every allowed MAC address.
8. Recovering a Port from Shutdown (err-disabled)
Method 1 — Manual Recovery
Switch(config)# interface FastEthernet0/1
Switch(config-if)# shutdown
Switch(config-if)# no shutdown
The brief shutdown clears the err-disabled state. The port returns to up after no shutdown. If the violating device is still connected and port security is still active, it will shut down again immediately.
Method 2 — Automatic Recovery (errdisable recovery)
! Enable automatic recovery for port security violations
Switch(config)# errdisable recovery cause psecure-violation
! Set the recovery interval (seconds — default 300)
Switch(config)# errdisable recovery interval 60
! Verify errdisable status
Switch# show errdisable recovery
With automatic recovery, the switch waits for the configured interval, then brings the port back up automatically. If the violating device is gone, the port stays up. If not, it immediately shuts down again.
9. Detection and Monitoring Commands
Switch# show port-security ! Summary of all secure ports
Switch# show port-security interface FastEthernet0/1 ! Detail: mode, count, violation count
Switch# show port-security address ! All secure MAC addresses and their ports
Switch# show interfaces FastEthernet0/1 status ! Current port status (err-disabled?)
Switch# show logging | include SEC ! Filter syslog for port security events
The show port-security interface output shows:
Port Security : Enabled
Port Status : Secure-up (or Secure-shutdown for err-disabled)
Violation Mode : Restrict
Aging Time : 0 mins
Maximum MAC Addresses : 1
Total MAC Addresses : 1
Configured MAC Addresses : 0
Sticky MAC Addresses : 1
Last Source Address:Vlan : 001a.2b3c.4d5e:10
Security Violation Count : 3
10. Troubleshooting Port Security Issues
| Symptom | Likely Cause | Resolution |
|---|---|---|
| Port is down (err-disabled) | Shutdown mode violation triggered | Remove unauthorised device, then shutdown/no shutdown or configure errdisable recovery |
| Device can't connect but port is up | Protect mode dropping frames — no alert | Run show port-security interface and check violation count; change to restrict for logging visibility |
| Continuous violation logs, port up | Restrict mode — unauthorised device repeatedly attempting access | Identify device from last source MAC in show output; decide whether to add it or block it |
| Port keeps shutting down after recovery | Violating device still plugged in | Remove the device first, then recover; or add its MAC to the allowed list if it's legitimate |
| Sticky MACs lost after reload | write memory (copy run start) not saved | Always save config after sticky MACs are learned: copy running-config startup-config |
11. Best Practices
- Use Protect only where uptime is paramount and you have other security controls in place; its silence makes it easy to miss ongoing violations
- Prefer Restrict for general user ports — you get full visibility into violations without disrupting legitimate traffic
- Use Shutdown for sensitive or high-value ports (server room access, finance workstations, network equipment management ports)
- Always configure
errdisable recovery cause psecure-violationwith a reasonable interval (300–600 seconds) to avoid permanent manual recovery overhead - Use sticky MAC to learn legitimate devices automatically; save config immediately after learning
- Monitor SNMP traps and syslog for restrict/shutdown violations — integrate with your NMS for alerting
- Set
maximum 1on all user-facing ports to prevent hub or switch connections that would enumerate multiple MACs. See MAC Address Table
Port Security Violation Modes Quiz
Related Topics & Step-by-Step Tutorials
Continue your port security and switch security studies:
- Port Security Overview — full overview of switchport port-security, maximum, and MAC types
- Sticky MAC Addresses — dynamically learning and locking secure MACs
- Port Security & Sticky MAC (Step-by-Step) — complete IOS configuration walkthrough
- MAC Address Table — how the switch builds its CAM table; MAC flooding attacks
- MAC Addresses — structure and format of hardware addresses
- show mac-address-table — view the current CAM table entries
- PortFast & BPDU Guard — STP port-level security features
- STP Overview — Spanning Tree Protocol and port roles
- VLANs — port security is applied per VLAN access port
- VLAN Tagging (802.1Q) — trunk ports do not support port security
- Access & Trunk Ports — port security only works on access ports
- SNMP Overview — receiving violation traps at your NMS
- SNMP Traps — configuring trap destinations for violation alerts
- SNMP Community Strings — required for SNMP trap forwarding
- Syslog — forwarding violation log messages to a centralised syslog server
- show logging — checking port security violation messages in the local log buffer
- Standard & Extended ACLs — complementary Layer 3 access control alongside port security
- DHCP Snooping — Layer 2 security feature that works alongside port security
- Dynamic ARP Inspection — prevents ARP spoofing on the same ports
- show running-config — verify port security configuration on an interface