Uses for Port Security
The first use case is to block unauthorized hubs, switches or access points from being used on the network. In this scenario, Port Security is configured to allow a set number of MAC addresses to come from a certain port. In most cases it would be set to two, one for the PC and one for the IP phone. Any MAC addresses past the first two seen would either be denied access to the network or cause the port to be err-disabled (more on the violation modes later). The allowed MAC addresses can either be statically assigned, dynamically learned, or dynamically learned and made permanent.
The other use case is to ensure that a secure piece of equipment like a credit card reader or biomedical device is the only device able to use the port. In this case, the port is usually setup for a static MAC address. Any other hosts are subject to the configured violation mode setup on the port. If needed, more than one MAC address can be statically assigned to a single port.
Configuring Port Security
Now let's take a look at how Port Security is configured on a switch port.
The first command after entering interface configuration turns Port Security on for the port. Next, the MAC address to be allowed is configured. Finally the last line sets the violation mode to protect. There are three modes: protect, restrict and shutdown.
SWITCH(config)# int Gi3/0/27 SWITCH(config-if)#switchport port-security SWITCH(config-if)#switchport port-security mac-address 0000.aaaa.bbbb SWITCH(config-if)#switchport port-security violation restrict
- Protect - When a violation of the Port Security rules is detected, the port will drop all traffic to the violating MAC addresses and note the violation in the logs. The port also stops learning MAC addresses even if the violation is only for a VLAN. As such Cisco does not recommend this mode.
- Restrict - When a violation of the Port Security rules is detected, the port will drop all traffic to the violating MAC address, note the violation in the logs, and send an SNMP trap. This is the recommended mode from Cisco versus Protect.
- Shutdown - When a violation of the Port Security rules is detected, the port is put into err-disabled state until either the engineer clears the port or the timer expires if errdiable recovery is configured.
Sticky MAC Addresses
This example is very similar to the first, but you will notice that instead of a MAC address, the keyword sticky is substituted. This configures the port such that the first MAC address it learns will become the secure MAC address for the port until changed by the network engineer. All other MAC addresses learned will be considered in violation. There is an implied default configuration of "switchport port-security maximum 1" in this configuration that limits the port to one mac address learned. If you wanted to let the port have more than one sticky MAC address, enter the command "switchport port-security maximum <number>".
SWITCH(config)# int Gi3/0/27 SWITCH(config-if)#switchport port-security SWITCH(config-if)#switchport port-security mac-address sticky SWITCH(config-if)#switchport port-security violation restrict
Aging MAC Addresses
Another twist on dynamically learned MAC addresses is to use aging to limit the number of devices on a port, but not necessarily restrict devices based on the MAC address. In this configuration the port is set to limit the number of MAC addresses allowed, but as MAC addresses are no longer seen for a set type they are aged out allowing new MAC addresses to be added to the port without a violation. The aging can either be absolute or based on inactivity.
In the above example, the port is set to age out a MAC address after 480 minutes go by regardless of activity.
SWITCH(config)# int Gi3/0/27 SWITCH(config-if)#switchport port-security SWITCH(config-if)#switchport port-security aging time 480 type absolute SWITCH(config-if)#switchport port-security violation restrict
This example shows the configuration to have the MAC address aged out 10 minutes after the last activity.
SWITCH(config)# int Gi3/0/27 SWITCH(config-if)#switchport port-security SWITCH(config-if)#switchport port-security aging time 10 type inactivity SWITCH(config-if)#switchport port-security violation restrict
Wrap Up
While Port Security is a very powerful tool, I have not seen it as widely deployed as one would think. I think part of that is lack of awareness and the other part is fear of taking down a production port automatically. With the right planning and knowledge, both can be overcome. I really suggest people consider adding Port Security to their port activation templates. Even if it is just to stop unauthorized hubs, switches and access points, there is definite benefit.
Nice post. Thanks
ReplyDeleteThanks a lot. Very good post
ReplyDelete