Securing Switch Ports with Port Security

14 minsSimneta AcademyOct 17, 2026

Protect your enterprise local area network from rogue devices. Configure Cisco switch port security with sticky MAC learning and shutdown violation mode to isolate unauthorized computers automatically.

Walk through almost any corporate office or school campus, and you will find dozens of live RJ45 Ethernet wall outlets scattered across conference tables, empty cubicles, and reception desks. While these exposed jacks offer convenient plug-and-play access for employees, they also represent a severe physical security risk. A visiting contractor or rogue intruder could unplug a desk phone, insert an untrusted laptop into the wall, and immediately start eavesdropping on internal company traffic.

Standard Layer 2 switches are designed to be friendly and helpful by default: they accept incoming frames from any network card and forward them across the local area network without asking questions. If an intruder attaches their own machine, the switch simply adds their hardware address to the MAC table and forwards their data packets directly into the corporate core.

To secure physical access points, network engineers deploy Cisco Port Security. By restricting the maximum number of MAC addresses allowed on an interface and binding specific hardware addresses to ports, the switch can detect unauthorized computers instantly and disable the physical link before any breach occurs.

Securing access ports requires understanding why dynamic trunk negotiation must be locked down first, how sticky MAC learning saves hardware bindings into active switch memory, and how different violation policies react when an unexpected frame hits the port.

Network Architecture Plan

SegmentInterfaceSubnet / AddressFunctional Role
Access Switch (SW1)FastEthernet0/1VLAN 1 (Port Security Active)Enforces MAC limiting and err-disable shutdown
Authorized WorkstationFastEthernet0192.168.1.10/24Legitimate corporate desktop with registered sticky MAC
Rogue Attacker LaptopFastEthernet0192.168.1.99/24Untrusted intruder device simulating physical cable tampering
1

Enforcing Static Access Mode

Before you can enable port security on any Cisco switch interface, you must explicitly configure that port as an access port using the command switchport mode access.

By default, Cisco switch ports operate in dynamic desirable or dynamic auto mode under the Dynamic Trunking Protocol (DTP). This allows them to negotiate 802.1Q trunking automatically if a neighboring switch connects.

Cisco IOS intentionally disables port security on dynamic or trunking interfaces because trunk links carry thousands of different MAC addresses from multiple VLANs. Explicitly locking the port into access mode guarantees that the interface is dedicated to a single client endpoint.

Once static access mode is locked in, enter the feature activation command switchport port-security. This turns on the security inspection engine for interface FastEthernet0/1.

Locking Port to Static Access Mode
Switch# configure terminal
Switch(config)# interface FastEthernet0/1
# Step 1: Disable dynamic DTP trunk negotiation
Switch(config-if)# switchport mode access
# Step 2: Activate port security evaluation engine
Switch(config-if)# switchport port-security
Switch(config-if)# exit

Parameter-by-Parameter Command Breakdown:

switchport mode access: Explicitly disables DTP trunk negotiation. This protects the switch against VLAN hopping attacks where an attacker tricks a port into trunk mode to intercept all VLAN traffic.
switchport port-security: Enables the port security state machine on this interface. Without this standalone command, setting limits or violation modes will have zero effect.
Verification Check: You can verify that port security is globally active on the port by running show port-security interface Fa0/1.
Field Architecture Insight

Prerequisite Reminder: If you attempt to run switchport port-security on an interface in dynamic mode, Cisco IOS rejects the command with the error: Command rejected: FastEthernet0/1 is a dynamic port.

2

Configuring Sticky MAC Learning

Network administrators have three ways to define allowed MAC addresses: static manual typing, dynamic memory learning, and Sticky MAC learning.

Manually typing twelve-character hexadecimal MAC addresses for hundreds of workstations across a campus is exhausting and prone to human typos. Dynamic memory learning forgets all addresses the second the switch reboots.

Sticky MAC learning provides the perfect operational balance. When you execute switchport port-security mac-address sticky, the switch observes the very first frame sent by the connected computer, learns its hardware MAC address automatically, and writes it directly into the running configuration.

Next, configure switchport port-security maximum 1. This restricts the port to exactly one authorized hardware device. If an employee connects a mini-switch under their desk to share their wall jack with a friend, the arrival of a second MAC address will trigger a security violation.

Configuring Sticky Learning and Device Limits
Switch(config)# interface FastEthernet0/1
Switch(config-if)# switchport port-security maximum 1
Switch(config-if)# switchport port-security mac-address sticky
Switch(config-if)# exit

How Sticky Learning Saves Administrative Time:

maximum 1: Enforces a strict hardware limit. The switch CAM table accepts only one secure MAC address on this port.
mac-address sticky: Converts dynamically learned addresses into static configuration lines in running-config (e.g. switchport port-security mac-address sticky 0050.7966.1001).
Saving Across Power Outages: Because sticky addresses are written to RAM, always execute write memory or copy running-config startup-config after devices connect so bindings persist after switch reboots.
Field Architecture Insight

Real-world field incident: A contractor plugged a personal consumer Wi-Fi router into an office cubicle jack so their phone could get wireless. The moment the router bridged multiple MACs, the switch err-disabled the port instantly and notified security.

3

Comparing Port Violation Modes

Cisco switches support three distinct security violation modes: Protect, Restrict, and Shutdown.

Each violation mode applies a different level of defensive action when an unauthorized source MAC address reaches the port:

1Protect: The switch quietly drops packets from the unknown MAC address. Legitimate traffic from the authorized machine continues, and no error counter or syslog notification is generated.
2Restrict: The switch drops unauthorized packets, increments the Security Violation Counter, and generates an automated Syslog trap to the network monitoring console.
3Shutdown: The enterprise security standard. The instant an unauthorized MAC address transmits a frame, the switch immediately places the port into an err-disable state, shutting down the physical network port and turning off the link LED.

The port remains completely disabled to both the intruder and the original user until an authorized network administrator logs into the console, investigates the incident, and manually resets the interface.

Configuring Violation Policy and Limits
Switch(config)# interface FastEthernet0/1
# Put interface into err-disable shutdown state upon security breach
Switch(config-if)# switchport port-security violation shutdown
Switch(config-if)# exit

Violation Mode Defense Matrix:

Protect: Packet Drop: YES | Increment Counter: NO | Syslog / SNMP Trap: NO | Port Shutdown: NO.
Restrict: Packet Drop: YES | Increment Counter: YES | Syslog / SNMP Trap: YES | Port Shutdown: NO.
Shutdown (Default): Packet Drop: YES | Increment Counter: YES | Syslog / SNMP Trap: YES | Port Shutdown: YES (Err-Disable).

In corporate offices, shutdown is strongly preferred because it visually alerts users with a dead link light and prevents attackers from attempting brute-force MAC spoofing.

Field Architecture Insight

Security Decision: While restrict mode keeps authorized computers working during a rogue probe, shutdown mode guarantees that any physical tampering alerts the helpdesk immediately.

4

Simulating the Security Violation

To test our defense policy in Simneta NetLab, generate normal traffic from the Authorized Workstation by pinging the switch IP. Open the switch CLI and confirm that FastEthernet0/1 has successfully recorded the workstation MAC address.

Now, disconnect the Authorized Workstation from port Fa0/1 and plug in the Rogue Attacker Laptop. Attempt to transmit a ping from the rogue machine.

Watch how the switch hardware responds within milliseconds to block the untrusted computer.

Terminal Session Output
Console Verification
Switch# show port-security interface FastEthernet0/1
Port Security : Enabled
Port Status : Secure-shutdown
Violation Mode : Shutdown
Aging Time : 0 mins
Secure MAC Address : 1
Security Violation Count : 1
Last Source Address:Vlan : 000C.29FE.11A2:1
Switch# show interfaces FastEthernet0/1 status
Port Name Status Vlan Duplex Speed Type
Fa0/1 Desktop Jack err-disabled 1 auto auto 10/100BaseTX

Analyzing the Err-Disable State:

Port Status Secure-shutdown: Confirms that the security engine detected an unauthorized frame and triggered the shutdown policy.
Security Violation Count 1: Records that exactly one security breach event occurred on this physical port.
Last Source Address 000C.29FE.11A2:1: Captures the exact MAC address of the intruder laptop, providing forensic evidence for security incident reports.
Status err-disabled: The switch ASIC disabled physical layer signaling immediately. The port is turned off in silicon, preventing the intruder from discovering internal IP ranges or probing corporate servers.
Field Architecture Insight

Syslog Trap Notice: Upon breach, the switch console logs: %PM-4-ERR_DISABLE: psecure-violation error detected on Fa0/1, putting Fa0/1 in err-disable state. Security Information and Event Management (SIEM) systems can page security guards automatically.

5

The Administrative Recovery Workflow

Once a port enters the err-disabled state, simply unplugging the rogue laptop and plugging the authorized workstation back in will not restore connectivity. The switch ASIC locks the port in hardware to prevent attackers from retrying different spoofed addresses.

To recover the port, an administrator must access the switch console, navigate to the affected interface, execute shutdown, and then execute no shutdown.

Review the recovery sequence to return the port to active production service.

Administrative Err-Disable Recovery Sequence
Switch# configure terminal
Switch(config)# interface FastEthernet0/1
# Cycle interface to clear the err-disable latch
Switch(config-if)# shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
Switch(config-if)# no shutdown
%LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Switch(config-if)# exit

How Interface Cycling Clears the Hardware Latch:

shutdown: Clears the err-disable hardware flag from the port controller register.
no shutdown: Re-enables electrical signaling and restarts auto-negotiation pulses.
Verification Check: Running show port-security interface FastEthernet0/1 confirms that the interface returns to Secure-up, restoring authorized desktop transmission while preserving the sticky MAC binding in running memory.
Automated Recovery Option: In large enterprise networks, administrators can enable automatic recovery with global commands: errdisable recovery cause psecure-violation and errdisable recovery interval 300, allowing ports to test themselves every 5 minutes.
Field Architecture Insight

Recovery Tip: Always verify that the rogue computer has been unplugged before issuing no shutdown. If the rogue laptop remains plugged in, the port will err-disable again the instant a frame is sent.

Key Takeaways: Port security safeguards access-layer switches by restricting port connectivity to known hardware MAC addresses, automatically disabling physical jacks when unauthorized hardware is detected.
#port-security #mac-address #sticky-mac #err-disable #layer-2-security #switch-hardening

Discussion & Community Notes

Ask questions, share configuration tips, or discuss this laboratory topology.

0 Comments
Posting as Guest • 1-level replies supported
Loading discussion thread...