Configure and Troubleshoot Port Security
Configure and Troubleshoot Port Security
Security
Companies use the network infrastructure to move information, even sensitive. As a
result, they are subject to hackers to attack more often than you might think.
Considering this, security becomes every day more important when creating a network.
Cisco offers us a great tool to implement security at the data-link layer: Port Security.
In this lab, we are going to learn what port security is, how it works, and how we can
implement and troubleshoot it.
To benefit the most from this article, download the lab with the link below. Then, follow
the article while completing the lab. Otherwise, just check out the explanation.
For this lab, we have to two switches but we manage only one of them.
As you can see from the topology above, we are working with two switches and five
computers. However, for the purpose of this lab, one switch is out of our control. This is
the “RogueSwitch”, that might be a switch a user connected in order to have more ports
on his desk. Obviously, this is something we don’t want, and we are going to block that
with port-security.
All PCs have a correct IP address in the VLAN 1 subnet (10.192.168.1.0/24), but no
default gateway. This is not needed since we are going to use only intra-VLAN
communication. The following table reports the details about the IP address
configuration.
1
Device Address
PC0 192.168.1.10
PC1 192.168.1.11
PC2 192.168.1.12
PC3 192.168.1.13
PC4 192.168.1.14
IP Address Configuration
The Requirements
For this lab, we are going to implement Port Security in several flavors. Specifically, we
are going to try four different configurations on four different ports. The only device we
are going to configure is Switch, as follows.
2
Port Security is a technology that restrict access to the network based on source MAC
address.
In other words, we are talking about a set of configuration commands you can
apply only to access ports. With these commands, the switch is going to inspect the
source MAC address on frames incoming on that port. You can configure how many
different MAC address to expect, or even which ones. Furthermore, you can configure
the behavior in case something is different from expected.
Port Security is not simply designed to control which devices can access the network.
We all know that a hacker can change the MAC address of its PC. Instead, Port
Security protects us from TCAM flooding directly, and from DHCP Starvation indirectly.
Besides creating instability, this exposes your data. Any traffic will be mirrored to all
other ports, so the hacker can listen to everything on the network. Obviously, we want to
prevent that. Port Security is designed to prevent TCAM flooding attacks, and it does it
is very effective. Since you can control the number of devices allowed on each port, you
can predict how many MAC addresses the TCAM will have to store.
DHCP Starvation alone creates outages, as clients won’t get IP addresses anymore.
However, it is often used in conjunction with DHCP spoofing. Once the trusted server is
KO with the starvation, an attacker can bring a rogue DHCP server into the network.
Then, he can configure it to put itself as the default gateway. Therefore, all the traffic
goes to the hacker, which may relay it to the correct destination. This way, users are
unaware while the hacker is inspecting their traffic.
3
Port Security is not designed to protect against these attacks. Cisco offers you different
tools, like DHCP snooping. However, since you can limit the device on a port, it will be
hard for a hacker to starve your server.
Command Description
switchport port- Set to “N” the number of MAC address to accept on this port. Default
security maximum is 1.
N
switchport port- Hardcode one MAC address to the port. You can specify one or more
security mac- MAC addresses, if so the switch will accept traffic only from them.
address
XXXX.XXXX.XXXX Without this command,all MAC addresses are accepted unless they
exceed the maximum.
switchport port- Write in the configuration the MAC addresses seen on the port, then
security mac- allow only them. Not compatible with hardcoded MAC address.
address sticky
4
Command Description
Switch(config)#
Switch(config)#interface FastEthernet 0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport port-security maximum 1
Switch(config-if)#switchport port-security violation protect
Switch(config-if)#switchport port-security mac-address sticky
Switch(config-if)#switchport port-security
Switch(config-if)#exit
Switch(config)#
This is a pretty good template. According to our requirements, we can apply this exact
template to all other ports, changing only the violation action. In fact, this is what we are
going to do in the next steps.
5
Configuring the “Restrict” port
Interface FastEthernet 0/2 faces PC1, and we need to configure it to generate alerts by
requirements. However, two different violation actions generate alerts on the violation.
We are talking about restrict and shutdown mode. The key difference is that shutdown
generates an alert, then shut down the port. For this port, we only want alerts, so we are
going to use restrict.
The switch will learn many sticky MAC addresses as many specified in the maximum
command.
As soon as the switch receives a packet, it will inspect it and learn the MAC address. In
this process, the switch stores the MAC in the running configuration. This MAC address
starts to be part of the configuration immediately but is not retained upon reboot.
Therefore, you must log in to your switch and save the configuration.
Now, issue show running-config to check out the Port Security configuration. As you
can see, there is no MAC address just yet.
6
This is all the configuration we created.
To make the switch learn MAC addresses, we need to generate some traffic. Open
PC0 desktop, then start the command prompt. From there, ping PC1 with
ping 192.168.1.11. This way, the switch will learn PC0’s MAC address and PC1’s MAC
address (from the response). After this ping, ping PC2 with ping 192.168.1.12. Then,
check the configuration of the switch again.
7
Cisco IOS automatically added the highlighted command.
Now, if we want, we can use write to save the configuration. At this point, the switch
will retain these MAC addresses even after a reboot. For the configuration part, this is
everything we need to know. Instead, we need to continue this lab with troubleshooting.
Imagine your network allow a single device on each port. A user, without informing you,
attached a small 8-ports switch to connect both desktop PC and laptop. This is
the Rogue Switch in our lab. We configured the port toward it (FastEthernet 0/4) with a
maximum of one MAC address. All we need to do to trigger the violation is to make both
PCs connected to that device generate traffic. We can do it by pinging PC3
(192.168.1.13) and PC4 (192.168.1.14) from PC1. As soon as you do, the interface will
turn red. Note that if RogueSwitch generates traffic by itself, you might trigger a violation
with a single ping.
8
The
red dots indicate that the interface is shut down (from Switch’s side).
9
Look for the “err-disabled” state in the interface status.
Err-disabled interfaces recover automatically every five minutes, and this is
configurable. Note that Port Security is not the only reason for an interface to go in this
state. The same interface will appear as simply “down/down” in show ip interfaces
brief. However, if you want to check all interfaces in bulk you can use show
interfaces status, but this command is not available in Packet Tracer.
The automatic recovery of err-disabled interfaces exists for a reason. Most of the time,
our users to generate violations, not hackers. For example, many users may connect an
extra switch in meeting rooms. Therefore, you want the interface to automatically
recover after a while. This is not a real security issue, as the hacker does not have the
time to complete the attack if he has to wait for the recovery.
However, you might want to manually recover an interface. To do that, simply turn it off
and then on (shutdown, then no shutdown). Note that this does not disable Port Security,
and another violation will shutdown the interface again (if the mode is shutdown).
10
Conclusion (and bonus tips)
In this article, we covered all the details you need to configure and troubleshoot Port
Security. We used several commands, both for configuring and troubleshooting this
powerful technology. Here’s a recap.
Now that we know all the secrets, we are ready to pause with topic related to switching
and start something a little bit more advanced: routing. In the next article in the CCNA
course, we will introduce just that!
11