VMware ESXi and vSphere Cluster Management
Cisco Switch Port Security Configuration and Violation Modes
Learn how to configure Cisco switch port security, assign secure MAC addresses, choose violation modes, verify status, and recover err-disabled ports.
What Port Security Does
Switch interfaces are commonly active when a switch is installed. Anyone who can reach an unused wall jack may therefore connect a device and obtain Layer 2 access to the connected VLAN. Physical access control, such as locked wiring closets and controlled jacks, remains important.
Port security is a Cisco Layer 2 access-control feature that limits the source MAC addresses allowed to send frames through a switch interface. A permitted address is called a secure MAC address.
Port security reduces unauthorized endpoint access, but it is not a complete security solution. It does not replace authentication, VLAN design, endpoint security, access control lists, monitoring, or physical security.
Prerequisites and Operating Requirements
Before configuring port security, understand Ethernet frame forwarding, MAC address learning, Cisco IOS configuration modes, access ports, VLANs, and saving configurations.
- Port security is configured separately on each switch interface.
- The interface should be configured as a static access port before port security is enabled.
- An access port carries traffic for one access VLAN and is normally used for an endpoint.
- The port must be operationally suitable for endpoint access. Exact behavior and command support can vary by Cisco IOS platform and software release.
Use the following sequence to enter interface configuration mode and make the port an access port:
configure terminal
interface FastEthernet0/1
switchport mode accessEnable Basic Port Security
After configuring the interface as an access port, enable port security:
configure terminal
interface FastEthernet0/1
switchport mode access
switchport port-security
endOn platforms where the default applies, enabling port security permits a maximum of one secure MAC address. Explicitly configuring the maximum is recommended when the intended design should be clear:
configure terminal
interface FastEthernet0/1
switchport port-security maximum 1
endAssigning Secure MAC Addresses
Static Secure MAC Address
A static secure MAC address is manually configured by an administrator. This is useful when a fixed device, such as a known workstation, must be bound tightly to a port.
configure terminal
interface FastEthernet0/1
switchport mode access
switchport port-security
switchport port-security mac-address 0011.2233.4455
endReplace 0011.2233.4455 with the authorized device's actual MAC address. A static binding is explicit and predictable, but it must be changed when the device is replaced.
Sticky MAC Learning
A sticky MAC address is learned dynamically by port security from the device currently connected to the interface. The switch treats the learned address as a secure entry and displays it as a sticky entry in the active configuration.
configure terminal
interface FastEthernet0/1
switchport mode access
switchport port-security
switchport port-security mac-address sticky
endGenerate traffic from the trusted endpoint if necessary, then inspect the learned entry:
show port-security interface FastEthernet0/1
show running-config interface FastEthernet0/1Sticky addresses can appear in the running configuration. Save the configuration after reviewing the learned address so it remains after a reload:
copy running-config startup-configSticky learning simplifies deployment when the initially connected device is trusted. It also creates an operational responsibility: replacing, docking, virtualizing, or moving the endpoint may require updating the sticky entry.
Static and Sticky Methods Compared
Set the Maximum Number of Secure MAC Addresses
The maximum controls how many secure MAC addresses may use an interface. A typical single-host wall jack should normally allow one address:
configure terminal
interface FastEthernet0/1
switchport port-security maximum 1
endA port legitimately used by an IP phone and a connected workstation may need a larger maximum. Set the smallest value that supports the design:
configure terminal
interface FastEthernet0/1
switchport port-security maximum 2
endAllowing multiple addresses provides flexibility but expands the number of devices that can share the port. A larger maximum can also make unauthorized access harder to distinguish from legitimate use. Confirm the phone, workstation, virtualization, docking station, or downstream-device design before increasing the limit.
Violation Modes
A security violation occurs when the switch receives traffic from an unauthorized source MAC address or when the number of observed secure MAC addresses exceeds the configured maximum.
Shutdown is the usual default violation action on supported Cisco IOS access-port configurations, but verify the actual platform and release. Configure the desired mode explicitly when a particular policy is required.
configure terminal
interface FastEthernet0/1
switchport port-security violation protect
endconfigure terminal
interface FastEthernet0/1
switchport port-security violation restrict
endconfigure terminal
interface FastEthernet0/1
switchport port-security violation shutdown
endPractical Example: One Authorized Workstation
Assume Host A is connected to FastEthernet0/1 on switch SW1, and its authorized MAC address is 0011.2233.4455. This configuration permits only that MAC address:
configure terminal
interface FastEthernet0/1
switchport mode access
switchport port-security
switchport port-security maximum 1
switchport port-security mac-address 0011.2233.4455
switchport port-security violation shutdown
endWith Host A connected, the port should operate normally. If Host A is removed and a different laptop sends traffic, the new source MAC address causes a violation. With shutdown mode, the interface enters err-disabled state.
Verification and Monitoring
Use an interface-specific command to inspect the port-security state:
show port-security interface FastEthernet0/1Inspect the port status, configured maximum, current secure MAC count, violation count, violation mode, and secure MAC addresses. A healthy active port is commonly shown as secure-up. A configured port without an active link may show secure-down. A port disabled by shutdown-mode port security is typically shown as secure-shutdown or otherwise identified as err-disabled, depending on platform and release.
List secure addresses across the switch with:
show port-security addressCheck general interface status for an err-disabled indication:
show interfaces statusCompare the normal MAC address table with port-security state when investigating unexpected learning:
show mac address-table interface FastEthernet0/1Recover from a Shutdown Violation
First identify and remove the unexpected device, or confirm through change control that it is legitimate. Do not reset the port without correcting the cause, because the same device can immediately trigger another violation.
After resolving the endpoint or authorization problem, administratively reset the interface:
configure terminal
interface FastEthernet0/1
shutdown
no shutdown
endRecheck the interface and port-security state:
show interfaces status
show port-security interface FastEthernet0/1If a replacement device is legitimate, remove or replace the obsolete static or sticky MAC entry according to the change-control policy before reconnecting the new endpoint. Use show running-config interface FastEthernet0/1 and show port-security address to locate the old entry.
Optional Automatic Err-Disabled Recovery
Some environments permit timed recovery from port-security err-disabled events:
configure terminal
errdisable recovery cause psecure-violation
errdisable recovery interval 300
endConfirm exact command support and defaults on the deployed Cisco IOS version. Automatic recovery should be used only when policy allows it. If the cause remains, the port can repeatedly disable and restore, potentially allowing repeated unauthorized attempts and creating an operational alert cycle.
Troubleshooting Common Problems
Port Becomes Err-Disabled After a New Device Is Connected
The likely cause is shutdown violation mode detecting an unauthorized MAC address or a secure-MAC maximum that has been exceeded.
show port-security interface FastEthernet0/1
show interfaces statusVerify the connected endpoint and its MAC address. Remove or authorize the unexpected device, adjust the secure-MAC configuration only when justified, and then perform the administrative shutdown/no shutdown recovery.
A Replacement Device Cannot Connect
A static or sticky entry may still identify the previous device as the only authorized address. Inspect:
show port-security interface FastEthernet0/1
show running-config interface FastEthernet0/1
show port-security addressRemove or replace the obsolete secure MAC entry according to policy, then validate the replacement endpoint.
An IP Phone and PC Cause Repeated Violations
The maximum may be too low for the legitimate number of source MAC addresses. Confirm that both devices are expected, inspect the secure-MAC count, and set a minimally sufficient maximum. Keep the violation mode appropriate for the required monitoring and enforcement level.
Sticky Entries Disappear After a Reboot
The learned entries were probably not saved to startup configuration. Compare:
show running-config interface FastEthernet0/1
show startup-configAfter reviewing the learned addresses, save the configuration with copy running-config startup-config.
The Port-Security Command Is Rejected
The interface may not be configured as an access port, or the switch platform and IOS release may have feature limitations. Check the interface configuration and confirm feature support:
show running-config interface FastEthernet0/1Configure the required access-port mode and verify the exact syntax for the deployed platform and release.
Design Recommendations and Exam Notes
- Use a static secure MAC binding for tightly controlled, fixed devices.
- Use sticky learning when the initial endpoint is trusted and simpler deployment is valuable.
- Use one secure MAC address for a normal single-host wall jack unless the design requires more.
- Use a larger maximum for legitimate multi-device arrangements, such as an IP phone with a connected workstation, while keeping the value as low as practical.
- Choose protect for silent blocking, restrict for blocking plus counters and notifications, and shutdown for strict enforcement with an err-disabled response.
- Account for legitimate MAC changes caused by hardware replacement, virtualization, docking stations, phones, and downstream devices.
- For exam questions, remember the sequence: configure access mode, enable port security, set the maximum or secure MAC address, select the violation mode, verify, and save when sticky entries must persist.
- Port security is per interface and is based on source MAC addresses; it is not user authentication and does not secure the entire network.