Black Friday: 50% off every workbook with code . Ends Nov 30, 23:59 ET. Buy Now

Last day: 50% off every workbook ends tonight at 23:59 ET. Code Buy Now

Skip to main content
intermediate Free PDF

Cisco Port Security: Violation Modes, Commands and Labs

Reviewed 2026-11-26

Direct answer
Cisco port security is a Layer 2 switch feature that limits which source MAC addresses can use a port, and how many. A frame from an unallowed MAC is dropped, and shutdown, restrict or protect mode decides whether the port is logged, kept up or err-disabled.

What Is Cisco Port Security?

Cisco port security is a Layer 2 switch feature that limits which source MAC addresses can send frames into a port, and how many. If a frame arrives from a MAC address that isn’t allowed, the switch drops it. Depending on the violation mode, it also logs the event or shuts the port down.

It’s off by default. It stops three common problems:

  • A rogue laptop. Someone plugs into a free wall socket. The MAC isn’t on the list, so the switch blocks it.
  • A mini switch under a desk. One wall port suddenly shows several MAC addresses and goes over its limit.
  • MAC flooding. An attacker sends frames with made-up source MACs to fill the MAC table. A small maximum stops the flood after the first few.

The switch reads only the source MAC of frames that enter the port. It doesn’t check who the device really is.

SettingDefault on a Cisco switch
Port securityDisabled on the port
Maximum secure MAC addresses1
Violation modeShutdown
LearningDynamic (sticky learning is off)
Aging time0 (aging is off)
Aging typeAbsolute
Static agingDisabled

Source: Cisco’s Catalyst 9300 port security guide for IOS XE 17.9. Your image may differ, so confirm with show port-security interface.

So with the defaults, the first device to send a frame wins the only slot. Any other device makes the port shut down.

Flow chart of how a Cisco switch checks the source MAC of each frame for port security
Cisco port security checks the source MAC of every frame: known, new with room, or new with a full port.

How Do You Configure Port Security on a Cisco Switch?

Set the port to access mode first, then turn port security on. Cisco’s guide says a secure port can’t be a dynamic-mode port, and a port left in the default dynamic auto mode is refused. It does allow static access ports and trunk ports.

SW1(config)# interface g0/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 sticky
SW1(config-if)# switchport port-security violation restrict

Here’s what each line does:

  1. switchport mode access makes the port carry one end device, not a trunk.
  2. switchport port-security turns the feature on with the defaults above.
  3. maximum 2 lets the port hold two secure MACs, for example a PC and a phone.
  4. mac-address sticky learns MACs and saves them in the running config.
  5. violation restrict drops bad frames, keeps the port up and logs each one.

Every secure MAC counts toward the maximum, including the ones you type by hand. If you want two typed MACs, set the maximum to at least 2 first.

Three commands to turn on Cisco port security: switchport mode access, switchport port-security and violation restrict
Three lines turn on Cisco port security: switchport mode access, switchport port-security and a violation mode.

Port Security Violation Modes: Shutdown vs Restrict vs Protect

A violation is a frame from a MAC that isn’t allowed, or a port that goes over its maximum. You choose one of three reactions with switchport port-security violation.

ShutdownRestrictProtect
Frames from the unauthorized MACDroppedDroppedDropped
Port stateErr-disabled (off)Stays upStays up
The legitimate deviceLoses its link tooKeeps workingKeeps working
Syslog messageYesYesNo
Violation counterIncreasesIncreasesDoesn’t increase
How the port recoversManually or with errdisable recoveryNothing neededNothing needed
DefaultYesNoNo

Source: the same Cisco Catalyst 9300 guide, IOS XE 17.9.

Cisco also has a fourth option, shutdown vlan. It err-disables only the VLAN where the violation happened, not the whole port.

Which violation mode should you choose?

SituationModeWhy
Server port, one known deviceShutdownAny other device is an alarm worth an outage
Reception desk that must stay up, but IT wants alertsRestrictThe port stays up and the log tells you
Lab port where extra devices are just noiseProtectQuiet, but you lose visibility

Protect hides attacks. A violation count of 0 and no log lines on a protect port doesn’t prove nobody tried. Cisco also advises against protect mode on trunk ports.

Comparison of Cisco port security violation modes: restrict and protect keep the link up, shutdown and shutdown vlan err-disable
Restrict and protect keep the link up. Shutdown and shutdown vlan err-disable the port or the VLAN.

Static, Dynamic and Sticky Secure MAC Addresses

A secure MAC address is a MAC the switch has accepted for a port. It can get there three ways.

StaticDynamicSticky
How it gets thereYou type itThe switch learns itThe switch learns it, then writes it to the config
Survives the port going downYesNoYes
In the running configYesNoYes
Ages outOnly with aging staticOnly if aging is onNo

Cisco removes dynamic secure MACs the moment a port disconnects, even when inactivity aging is on. That one fact explains most “why did the wrong device get in?” questions. After a link flap, the first device to talk becomes the new secure MAC.

Sticky has two traps. The learned MAC lives only in the running config, so save it with copy running-config startup-config or you’ll lose it at the next reload. And sticky locks in the first device it sees, even if that device was the wrong one.

Which type fits your port?

  • One fixed server: static MAC, maximum 1, shutdown mode.
  • One desk PC, no typing: sticky, maximum 1.
  • Hot desks that change over time: dynamic with inactivity aging.
Static, sticky and dynamic secure MAC addresses compared: dynamic MACs are removed when the link goes down
Only dynamic secure MAC addresses are forgotten when the link goes down. Static and sticky ones stay.

How Do You Fix a Port in err-disabled State?

A port in err-disabled state was shut down by a violation. The log shows psecure-violation as the reason. Fix it in this order:

  1. Find the offender. Run show port-security interface g0/1 and read the Last Source Address:Vlan line. After a violation, it names the device that caused it.
  2. Remove that device. Unplug it, or stop it in your lab.
  3. Re-enable the port. Enter shutdown, then no shutdown, on the interface.

Order matters. A dynamic secure MAC is forgotten when the port goes down, so after no shutdown the first device to talk wins. If the intruder is still plugged in and talks first, the port now trusts the intruder.

To bring ports back by themselves, turn on errdisable recovery. Cisco names the command in its guide:

SW1(config)# errdisable recovery cause psecure-violation
SW1(config)# errdisable recovery interval 30

Recovery doesn’t check that the offender is gone. It only turns the port on again. If the wrong device keeps talking, the port goes down, comes up, hits a violation and goes down again, over and over.

Port Security Aging: Absolute vs Inactivity

Aging gives a dynamic secure MAC a lifetime. When it ends, the MAC is removed and the slot is free for a different device. Cisco’s valid range for the aging time is 0 to 1440 minutes, and 0 means aging is off.

Absolute (default)Inactivity
Timer startsWhen the MAC is learnedAt the last frame from that MAC
Reset by trafficNoYes, every frame resets it
A busy deviceRemoved, then learned again by its next frameNever removed
A silent deviceRemoved when time is upRemoved after the full silent period

Cisco states that the switch doesn’t support aging of sticky secure addresses. Static addresses age only when you add switchport port-security aging static.

SW3(config-if)# switchport port-security aging time 2
SW3(config-if)# switchport port-security aging type inactivity

Use inactivity aging on hot desks and meeting rooms. When the old laptop goes quiet, its slot frees up for the next one.

How Do You Verify Port Security?

Run these five commands. They answer most questions without a debug.

CommandWhat it shows
show port-securityOne line per secure port: maximum, current count, violations, action
show port-security interface g0/1Status, mode, aging, counts and the last source MAC
show port-security addressSecure MACs with their remaining age
show mac address-table secureThe secure MACs in the MAC table
show interfaces status err-disabledPorts shut down by an error, with the reason

On show port-security interface, read the Port Status line. Secure-up means working, Secure-down means nothing is connected, and Secure-shutdown means a violation shut the port down. If Total MAC Addresses equals Maximum MAC Addresses, the port is full, and the next new MAC is a violation.

In show mac address-table secure, sticky MACs show as STATIC. Don’t read that as “typed by hand”. Check the Configured and Sticky counts, or the running config, to tell them apart.

Can Port Security Stop MAC Spoofing?

No. Port security trusts the source MAC in the frame. A device that copies an allowed MAC looks identical to the switch. Anyone who can read a label on a device, or watch traffic, can learn an allowed MAC.

So treat port security as a cheap first fence, not a lock. It stops accidents and casual attacks. For stronger control, add 802.1X for real authentication, and DHCP snooping and Dynamic ARP Inspection for fake DHCP and ARP messages. Our DHCP snooping PDF shows how those features compare with port security.

Cisco lists it in the exam blueprint. CCNA 200-301 v1.1 has objective “5.7 Configure and verify Layer 2 security features (DHCP snooping, dynamic ARP inspection, and port security)”. The v2.0 blueprint has “4.7 Configure Layer 2 security features” with “4.7.e Port security”. See Cisco’s v1.1 exam topics and v2.0 exam topics. Our free CCNA 200-301 PDF and CCNA practice test PDF cover the rest of that blueprint.

Cisco Port Security Cheat Sheet

JobCommand
Make the port an access portswitchport mode access
Turn port security onswitchport port-security
Set the maximumswitchport port-security maximum <n>
Add a static MACswitchport port-security mac-address <mac>
Turn sticky learning onswitchport port-security mac-address sticky
Set the violation modeswitchport port-security violation shutdown|restrict|protect
Set the aging time (minutes)switchport port-security aging time <n>
Set the aging typeswitchport port-security aging type absolute|inactivity
Let static MACs ageswitchport port-security aging static
Turn automatic recovery onerrdisable recovery cause psecure-violation
Re-enable a port by handshutdown, then no shutdown
Clear dynamic secure MACsclear port-security dynamic interface <int>
Remove port security from a portno switchport port-security

For the rest of the everyday switch and router commands, see our Cisco commands cheat sheet PDF.

What Are the Most Common Port Security Mistakes?

MistakeWhat happensFix
Typing switchport port-security on a dynamic-mode portIOS rejects the commandSet switchport mode access first
Re-enabling the port with the intruder still connectedThe intruder talks first and becomes trusted, or the port shuts down againRemove the device, then shutdown and no shutdown
Using protect mode and trusting a count of 0Attacks go unseenUse restrict if you want alerts
Forgetting copy running-config startup-configSticky MACs vanish at reloadSave after the MACs are learned
Setting maximum 1 behind a mini switchThe second device triggers a violationSet the maximum to the number of devices you allow
Leaving a stale dynamic MAC on a port with no agingA replacement device is blocked even though the old one is goneTurn on inactivity aging, or clear the dynamic MACs

What Does the Free PDF Cover, and Where Does It Stop?

The PDF teaches port security from the ground up, then makes you practise it. It covers why port security exists, enabling it, reading the show commands, err-disabled recovery, the violation modes, aging, sticky MACs and the MAC table. After the theory, it gives you seven labs on one three-floor network, break-it-then-fix-it drills, a master test matrix and a quick reference.

Here’s where it stops. The labs are written for a GNS3 build with an IOS Layer 2 switch image, so you need to bring your own lab software and images. Our guide to adding router and switch images to EVE-NG covers that side. Voice VLANs and per-VLAN limits get only a short preview. 802.1X, DHCP snooping and Dynamic ARP Inspection aren’t configured at all.

Do you want the next step? The CCNA Lab Workbook has a security lab that covers port security and DHCP snooping, plus the rest of the CCNA topics in lab form.

Frequently asked questions

What is Cisco port security?
Cisco port security is a Layer 2 switch feature that limits which source MAC addresses can send frames into a port, and how many. It's off by default. A frame from an unallowed MAC is dropped, and the violation mode decides what else happens.
How do I configure port security on a Cisco switch?
Set the port to access mode with switchport mode access, then enter switchport port-security. Add switchport port-security maximum , mac-address sticky and violation restrict as needed. Cisco refuses the command on a port left in dynamic mode.
What are the three violation modes?
Shutdown, restrict and protect. Shutdown err-disables the port and is the default. Restrict drops bad frames, keeps the port up and logs each violation. Protect drops them silently, with no log and no counter.
What are the three types of secure MAC address?
Static (you type it), dynamic (the switch learns it and forgets it when the port goes down) and sticky (the switch learns it and saves it in the running config).
How do I show port security on a Cisco switch?
Use show port-security for a summary and show port-security interface for one port. show mac address-table secure lists the secure MACs.
How do I fix a port that's err-disabled by port security?
Remove the offending device first. Read its MAC on the Last Source Address:Vlan line, then enter shutdown and no shutdown on the interface. Or turn on errdisable recovery cause psecure-violation so the switch re-enables it by itself.
How do I remove port security from an interface?
Enter no switchport port-security on the interface. To wipe the whole port back to defaults, use default interface , then set the access mode again.
What is a sticky MAC address?
A sticky MAC is a secure MAC the switch learns and then adds to the running config. It survives a link flap. Save it with copy running-config startup-config or it's lost at the next reload.
Can port security stop MAC spoofing?
No. It reads only the source MAC, so a device that copies an allowed MAC looks the same to the switch. Add 802.1X, DHCP snooping and Dynamic ARP Inspection for stronger control.

Questions about this PDF

No questions yet. Ask the first one.

Ask a question

Your email address won't be published. We review every question before it appears. How we handle your data. Required fields are marked

Reviewed by

CCDE/CCIE

How to cite this resource

SMEnode Labs (2026). Cisco Port Security: Violation Modes, Commands and Labs. SMEnode Labs. https://smenode-labs.com/free-pdf/networking/cisco-port-security/

APA

SMEnode Labs. (2026). Cisco Port Security: Violation Modes, Commands and Labs. SMEnode Labs. https://smenode-labs.com/free-pdf/networking/cisco-port-security/

BibTeX

@misc{smenodelabs2026,
  title = {Cisco Port Security: Violation Modes, Commands and Labs},
  author = {{SMEnode Labs}},
  year = {2026},
  url = {https://smenode-labs.com/free-pdf/networking/cisco-port-security/},
  note = {SMEnode Labs}
}