MAC Map
Notes from 2009–10

Protect your MAC tables: CAM overflow and port security

A switch's MAC address table has a fixed size. Fill it with fake entries and the switch starts behaving like a hub. Port security is the fix.

Published

Every switch keeps a table of which MAC address was last seen on which port. Cisco calls it the CAM table, others call it the MAC address table or forwarding database. It is what lets a switch send a frame to one port instead of all of them. It is also finite.

How the table fills

The switch learns from the source address of each frame. A new address gets a new entry; entries age out after a few minutes of silence, five by default on many switches. Normal networks use a small fraction of the space.

The overflow attack

Tools such as macof send tens of thousands of frames per second, each with a random source address. Every one is learned. When the table is full, the switch has nowhere to record real hosts, so frames for them are treated as unknown unicast and flooded out of every port in the VLAN. A machine that was only meant to see its own traffic now sees everyone’s.

Port security

The standard defence is to cap how many addresses one access port may learn:

interface GigabitEthernet0/5
 switchport mode access
 switchport port-security
 switchport port-security maximum 2
 switchport port-security violation restrict
 switchport port-security mac-address sticky
  • maximum 2 allows a PC and an IP phone behind it.
  • violation restrict drops the extra addresses and logs them; shutdown disables the port instead.
  • sticky writes the learned addresses into the running configuration so they survive aging.

Checking the table

switch# show mac address-table count
switch# show port-security interface GigabitEthernet0/5

A sudden jump in the count, or thousands of entries on one access port, is the signature of a flood. Look at a few of those addresses in the checker: randomly generated ones often have the multicast or local bit set at random, which no real network card would do.

For how hosts and switches use these tables day to day, see ARP and CAM tables.

Check an address in the MAC Map checker