Port Security Fundamentals

Learn how to configure port security on managed switches to limit MAC addresses per port and prevent unauthorized device access.

1. Executive Summary & Objective

In an era of sophisticated external threats, internal network security is frequently underestimated. The physical access layer—specifically the ubiquitous Ethernet ports scattered across office spaces, conference rooms, and hallways—provides an immediate, unimpeded entry point into the corporate network. Without strict Layer 2 access controls, any individual can plug in an unauthorized laptop, a rogue access point, or a malicious appliance and instantly gain lateral access to internal subnets.

The core objective of this module is to master Port Security, a foundational Layer 2 defense mechanism that restricts access based on Media Access Control (MAC) addresses. By the conclusion of this deep-dive, you will possess the expertise to implement, tune, and troubleshoot Port Security on enterprise switching infrastructure. You will learn to lock down edge ports, proactively prevent MAC address flooding attacks, and establish a baseline physical security posture that prevents unauthorized hardware from ever communicating on your network.

2. Core Concept & Theory (The “Why”)

The Inherent Vulnerability of Ethernet Switching

Traditional Ethernet switches operate on a model of absolute trust and dynamic learning. When a switch receives a frame on a port, it inspects the Source MAC address and adds it to its Content Addressable Memory (CAM) table. This table maps MAC addresses to physical interfaces, allowing the switch to forward frames efficiently rather than broadcasting them.

However, this dynamic learning process has no built-in authorization mechanism. If an attacker connects to a port, their MAC address is learned instantly. Furthermore, an attacker can launch a CAM Table Overflow Attack (using tools like macof). By generating thousands of frames per second, each with a randomly spoofed Source MAC address, the attacker forces the switch to exhaust its CAM table capacity. Once the CAM table is full, the switch cannot learn any new, legitimate MAC addresses. To ensure connectivity, the switch fails open, meaning it begins broadcasting all incoming unicast traffic out of every port—effectively behaving like a legacy hub. This allows the attacker to passively sniff highly sensitive data traversing the VLAN.

The Port Security Mechanism

Port Security directly mitigates unauthorized access and CAM flooding by strictly governing the MAC address learning process on a per-port basis. It enforces two primary constraints:

  1. Quantity Limit: The administrator specifies the maximum number of unique MAC addresses permitted to send traffic through a given port (e.g., maximum 1 for a standard desktop, maximum 2 for an IP phone with a daisy-chained PC).
  2. Identity Verification: The administrator can statically define which specific MAC addresses are allowed, or allow the switch to dynamically learn and “stick” to the first devices it sees.

When a violation occurs (either an unapproved MAC attempts communication, or the MAC limit is exceeded), the switch instantly reacts according to a pre-defined penalty mode, isolating the threat at the edge.

3. Architecture & Topology (Visualizing)

Consider a typical office branch topology:

  • Distribution Switch: Aggregates access switches, routes between VLANs.
  • Access Switch: Provides direct connectivity to endpoints.
  • Endpoints: Corporate Workstations, IP Phones, Network Printers.
  • Threat Actor: A visitor in the lobby attempting to plug a personal laptop into a network jack intended for an IP phone, or a disgruntled employee plugging in a 5-port unmanaged switch to connect multiple unauthorized devices.

Deployment Strategy: Port Security is an edge technology; it is applied exclusively on access ports (or trunks in very specific, specialized scenarios). It is never applied to uplinks between switches, as uplinks carry traffic for hundreds of MAC addresses.

If the disgruntled employee plugs an unmanaged switch into GigabitEthernet1/0/5 and connects three laptops, but the port is configured with a maximum of 1 MAC address, the switch will learn the MAC of the first laptop. When the second laptop sends a frame, the switch detects a violation and triggers the configured security action, severing the connection before malicious activity can proliferate.

4. Command Execution & Deployment (The “How”)

Configuring Port Security on Cisco IOS involves enabling the feature, setting the threshold, choosing how MAC addresses are learned, and defining the penalty.

Step 1: Enable Port Security

Port Security requires the interface to be statically defined as an access port or a trunk. It cannot be enabled on a dynamic port.

Switch(config)# interface GigabitEthernet1/0/5
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security

Step 2: Define the Maximum MAC Limit

By default, the maximum is 1. If an IP phone and a PC are connected to the same port, you must increase this.

Switch(config-if)# switchport port-security maximum 2

Step 3: Configure MAC Address Learning (Sticky)

Instead of typing out 48-bit MAC addresses manually, the “sticky” feature tells the switch to dynamically learn the first connecting MACs and instantly save them to the running configuration.

Switch(config-if)# switchport port-security mac-address sticky

Step 4: Define the Violation Mode

You must explicitly tell the switch what to do when a violation occurs. There are three modes:

  • Protect: Drops frames from unauthorized MACs. No log message is generated. (Silently drops).
  • Restrict: Drops frames from unauthorized MACs. Increments a violation counter and generates an SNMP trap/Syslog message. (Loud drop).
  • Shutdown (Default): The port immediately transitions into an err-disable state, shutting down completely. This is the most secure but requires administrator intervention to restore.
Switch(config-if)# switchport port-security violation restrict

Step 5: Automate Recovery (Optional)

If using the shutdown mode, you can configure the switch to automatically re-enable the port after a timeout, reducing helpdesk tickets.

Switch(config)# errdisable recovery cause psecure-violation
Switch(config)# errdisable recovery interval 300

5. Verification & Troubleshooting

Robust verification ensures that legitimate devices are locked in and the correct policies are applied.

1. Verifying Global Port Security Status:

Switch# show port-security

This provides a summary table of all interfaces with port security enabled, showing the configured max limit, the current number of learned addresses, and the violation action.

2. Detailed Interface Inspection:

Switch# show port-security interface GigabitEthernet1/0/5

This is the most critical troubleshooting command. It displays the port status (Secure-up or err-disable), the specific violation mode, and the violation counter. If a port is misbehaving, this output will tell you if a security violation is the root cause.

3. Viewing Learned MAC Addresses:

Switch# show port-security address

This lists exactly which MAC addresses are secured to which ports, and whether they were configured manually, dynamically, or via the sticky feature.

Troubleshooting Scenario:

  • Symptom: A user complains their internet is completely down. The port LED is off.
  • Root Cause: The user brought their home laptop to work and swapped the ethernet cable from their corporate desktop. The port security violation mode was set to shutdown.
  • Resolution: Verify the err-disable state using show interfaces status err-disabled. Instruct the user to plug the corporate PC back in. Manually reset the port by going into interface configuration mode, issuing a shutdown command, followed by a no shutdown command.

6. Sandbox / Interactive Lab Context

To solidify these concepts, build a lab scenario mimicking an enterprise edge constraint.

Lab Execution:

  1. Connect a single PC to a switch port (Gi0/1).
  2. Configure Port Security on Gi0/1 with a maximum of 1 MAC address, enable sticky MAC learning, and set the violation mode to shutdown.
  3. Generate traffic from the PC (e.g., ping the switch’s VLAN interface).
  4. Execute show running-config interface Gi0/1. You will see the PC’s MAC address has been permanently written into the configuration file by the sticky feature.
  5. Simulate an intrusion: Disconnect the PC and connect a totally different PC (or change the virtual MAC address of the original PC) to the same port.
  6. Attempt to ping the switch again. The ping will fail immediately.
  7. Observe the switch console. A Syslog message will appear indicating a psecure-violation and the port will transition to down/down (err-disabled).
  8. Practice the recovery process by bouncing the port (shutdown / no shutdown) to restore service.

🧪 Want to practise this on your own computer? See how to set up your lab →

🤖

Need clarification? Ask GT

Hi, I'm GT — your AI tutor for Port Security Fundamentals. What would you like to know?
📝

Knowledge Check

1 of 4

What threat does port security on an access port primarily stop?

Report a problem

About: /lessons/port-security-fundamentals