Watch on Instagram

Network Bytes · Episode 58 · CCNA 5.7

"Port security"

Port security lets a switch port remember which MAC addresses are allowed and how many. Learn the default limit of one, sticky learning, and the three violation modes: shutdown, restrict and protect.

Posted · About a 1 minute watch, 3 minute read · Take the quiz

The strange laptop in the wall jack

Picture an office wall jack wired to a switch port. Normally, anyone who plugs a laptop into it gets on the network: the switch simply forwards their frames. Port security (switchport port-security on a Cisco access port) changes that. The port now remembers a list of secure MAC addresses that may use it, plus a maximum: how many different addresses it will accept.

How the port learns its guest list

The default maximum is 1 secure MAC address. There are three ways an address gets on the list:

  • Static: you type it in, for example switchport port-security mac-address aaaa.bbbb.cccc.
  • Dynamic: the port learns the first address it sees, but only keeps it in memory, so it is lost when the switch restarts.
  • Sticky: the port learns the first address it sees and keeps it, writing it into the running configuration (switchport port-security mac-address sticky). Save the config and it survives a reload.

Violations and the shutdown mode

A frame from a new MAC address once the port is already at its maximum is a violation. What happens next depends on the violation mode. The default is shutdown: the port is put into the err-disabled state, so it carries no traffic at all, the violation counter goes up, and the switch sends a syslog message and an SNMP trap. The port stays off until an admin brings it back, with shutdown then no shutdown on the interface, or until errdisable recovery is configured to do it automatically.

Gentler modes: restrict and protect

  • Restrict drops the stranger's frames, logs an alert and counts the violation, but the port stays up for the allowed devices.
  • Protect also drops the stranger's frames and keeps the port up, but does it silently: no log message and no counter.

Shutdown is the safest default because nobody can miss an err-disabled port; restrict and protect trade that for keeping the allowed users online.

Try it yourself

If you have Cisco Packet Tracer (free with a Cisco Networking Academy account), connect one PC to a switch access port and enter switchport mode access, switchport port-security and switchport port-security mac-address sticky. Ping from the PC, then run show port-security interface and show running-config and look for the sticky MAC line the switch wrote for you.

Good to know

  • Cisco port security works on access ports (and also on trunk ports) once switchport port-security is enabled.
  • The default maximum is 1 secure MAC address; addresses can be static, dynamic or sticky (learned and written to the running config).
  • Violation modes: shutdown (default; the port goes err-disabled, the violation counter increments, a syslog message and SNMP trap are sent; recover with shutdown/no shutdown or errdisable recovery), restrict (drops and logs, counter increments, port stays up), protect (drops silently).
  • Some platforms also offer shutdown vlan, which disables only the violating VLAN on the port.
  • Simplified in the video: a "third device" on one port usually means a hub or small switch has been plugged in behind the wall jack.

For CCNA learners

This lines up with CCNA 200-301 exam topic 5.7, configure and verify Layer 2 security features (DHCP snooping, dynamic ARP inspection, and port security): know the default maximum, how sticky learning works, and what each violation mode does to the port and to the offending frames.

Answer to the comment question

0. The port allows two MACs. When the third device's MAC shows up, that is a violation, and in shutdown mode the whole port goes err-disabled. That cuts off every device behind it, including the two allowed ones, until an admin re-enables the port (or errdisable recovery brings it back).

Test your knowledge

Quick quiz: "Port security"

4 multiple-choice questions. Pick one answer for each, then check how you did.

1What is the default maximum number of secure MAC addresses on a Cisco port-security port?
2What does "sticky" learning do?
3In the default violation mode, what happens to the port?
4Which mode drops the stranger's frames without logging anything?

Sources

Video transcript

What happens when someone plugs a strange laptop into an office wall jack?

Normally, the switch lets it talk. Port security changes that. The switch port remembers which MAC addresses are allowed, and how many.

The default limit is one. You can type the address in, or let the port learn the first one it sees and keep it: that's sticky.

A new MAC past the limit is a violation. In the default mode, shutdown, the port turns off until an admin turns it back on.

There are gentler modes. Restrict drops the stranger's frames and logs an alert. Protect drops them silently.

A port allows two MACs, in shutdown mode. A third device appears. How many devices can still use that port? Comment your answer below!

That's your byte.

More from Network Bytes

All Network Bytes lessons