I recently started reevaluating how we do port security as a result of a recent customer's information security audit. We normally turn on port security and set the maximum MAC addresses to 1 (the default) or 2 (if there is an IP phone connected). The default behavior is to disable the port when the MAC changes or if the number of concurrent MAC’s exceeds the maximum.
However during testing I discovered this didn’t work exactly like I expected. Port security was enforced as long as a device stayed connected to the port. If the port was disconnected, the switch would remove the pre-existing MAC’s and ANY new device could connect, as long as the maximum was not exceeded. While this prevents unauthorized hubs and switches, it doesn’t prevent someone from unplugging a device and plugging in a different unauthorized device.
The solution to this is to use the sticky option on the port security interface command: [more]
switchport port-security – enables port security, optional “maximum <n>” to set the max greater than 1
switchport port-security mac-address sticky – turns on the sticky MAC feature
After enabling, you will notice the currently connected MAC address(es) will appear in the running config:
- switchport port-security
switchport port-security mac-address sticky
switchport port-security mac-address sticky 0080.6433.xxxx
This will stay in the config until the switch is rebooted, so it’s important to write the config.
Other related commands:
show port-security address – lists all the learned MAC addresses by interface
show port-security interface fa0/1 – shows the detailed port security settings for an interface, including enable/disable status
clear port-security sticky interface fa0/1 – clears the learned sticky MAC addresses, must be done prior to a shut/no shut to re-enable a port disabled due to port security
When you use sticky MAC addresses you'll want to make sure that the MAC addresses are cleared off of a switch when a device is moved. We had a laptop that was moved from one client location to another and one of the distribution switches was thinking the device was plugged into the old switch and the other distribution switch thought it was plugged ito the new switch. This created a situation where some network traffic was reaching the laptop and some was going into a black hole. After clearing the the sticky MAC addresses on the old switch the problem was resolved.
Update: You might also be interested in a couple stick MAC address tips.