← Module 02 · Layer 2: Data Link

Switch Port Security

A switchport will happily learn as many MAC addresses as devices plug into it. Port security is what puts a limit on that.

What it actually restricts

Recall from Ethernet Frame & MAC Addressing that a switch learns a MAC (Media Access Control) address for whatever port it sees that address arrive on. Nothing stops someone from plugging an unauthorized laptop into an open conference-room jack, or worse, plugging in a cheap unmanaged hub to fan one jack out to several devices. Port security caps how many MAC addresses a single port is allowed to learn, like a keycard reader that locks the door the moment a sixth unrecognized badge tries to swipe through, when only five badges were ever supposed to exist for that door.

How addresses get allowed onto a port

What happens on a violation

If a port is already at its MAC limit and a new, unrecognized address shows up, one of three violation modes decides what happens next:

Port, max: 1 OK learned MAC NEW unrecognized MAC: violation
The port already learned one MAC at its limit of 1. A second device shows up on the same port and trips a violation.
ModeWhat happens
ProtectSilently drops traffic from the offending MAC. No log, no counter.
RestrictDrops the traffic, but also logs it and increments a violation counter.
Shutdown (default)Puts the entire port into err-disabled state. It stops passing any traffic at all until an administrator manually re-enables it.
WHY THIS MATTERS BEYOND ONE ROGUE LAPTOP

Port security is also the first line of defense against MAC flooding: an attacker deliberately sending frames from thousands of fake source MACs to overflow a switch's MAC table, forcing it to fail open and flood everything like a hub. Capping learned addresses per port stops that flood at the one port it's coming from.