How Switch Port Security Can Save You from Cyber Attacks

Introduction to Switch Port Security

Nowadays, networks are the core elements of businesses, which ensures seamless communication and data transfer. However, if our switches are insecure, then it will open a door for hackers. Hackers can easily connect to the switches, leading to data breaches and unauthorized access. Cisco switch ports are turned on by default, due to which any PC can connect to it. The switch port security feature enables our switches to permit or deny any computer connected to it within a network. In this article, we will know how to configure switch port security on Cisco switches step-by-step.

How Does Switch Port Security Work?

A switch learns the MAC addresses of each device connected to its ports. It allows only that device’s MAC address to communicate on that port. However, if an unauthorized device’s MAC address tries to connect to the same port, then port security will disable that port.

There are different types of port policy violation rules, which tell the switch what to do if the number of MAC addresses exceeds the configured limit of pre-configured MAC addresses. These rules help to protect our network switches from unauthorized access.

We cannot implement port security on trunk ports, Etherchannel, and switch port analyzer ports. It only works on end-point device interfaces such as access ports.

Violation Rule

Comparison of Modes

Comparison Modes

Static vs. Dynamic MAC-Address Allocation: Which is Better?

Switch learns MAC addresses in two ways under port security, which are static and dynamic (sticky):

Static Learning: In static allocation, we define the maximum number of MAC addresses to be learned by the switch. It is manual work, which requires more attention.

Dynamic Learning (Sticky): The word “sticky” is added at the end of the command. When we use this feature, the switch will learn MAC addresses automatically. However, when it reaches its maximum number of MAC addresses, it will stop storing more MAC addresses.

How to Configure Switch Port Security (Static)

We will configure the following lab topology from Layer 2 security. It consists of one switch, one hub, and four computers. Later, we will add one more PC to the existing topology.

 switch port security lab diagram

Check and note all the MAC addresses of each PC as below in the screenshot:

mac address

The above is the PC0 MAC address; in the same way, check and note all the IP addresses of each PC as shown below. Later we will use the following MAC or physical addresses in the port security.

PCs mac address

Create VLAN 2 on the switch.

creating vlan 2

Configure the port fast Ethernet 0/1 as access port and assign it to the Vlan 2.

configuring fastethernet 0 1 as access port

Enable the port security on the above port (Fast Ethernet 0/1).

Enabling Switchport Security

Set the maximum number of addresses to be allow on fast Ethernet 0/1;

settuing up the max number of MAC addresses allowed on port

Configure the default violation mode, which is “shutdown”;

Now, manually associate the below addresses with the port security. This is the static way where we give addresses to the switch. The switch is not allowed to learn MAC addresses automatically.

 static mac addresses

As we have configured port security successfully on the switch. Now verify it through the command “show port-security interface fast Ethernet 0/1”.

show switch port security

Handling Security Violations

If an unauthorized device (such as a new PC (PC4)) attempts to connect to the port fast Ethernet 0/1 as below in the diagram,. Then the port will go into the “err-disable” state, effectively blocking the device.

 add 5th PC to the topology

As we connect PC4 to the hub, which is connected to the fast Ethernet 0/1 interface of the switch, the interface goes down. Let us check its status through the following command:

check on switch show port-security

The interface violation mode is “shutdown,” and it has learned its MAC address. Similarly, the security violation count is “1.”

Run another following command to check the state of the interface:

 show interface fastethernet 0 1 status

The interface is in an err-disabled state. How to recover it? Let us follow the below steps.

First, remove the PC4 as shown below in the screenshot;

remove pc5 from the toplogy

Secondly, go to the interface mode of fastetethernet 0/1, and first “shutdown” it and then “no shutdown” it through the following steps:

shutdown and no-shutdown the interface

The interface has been changed to “upstate, which you can check through the following command:

 show interface status

Before few seconds ago, the interface was in an err-disabled state, and now it is in operation mode because its status is “connected”.

Alternatively, if you want to recover the interface from the err-disable state automatically after some interval of time, use the below command. (Note: this feature command is not supported in Cisco Packet Tracer):

 interval command

Sticky Command (Dynamic)

In the previous commands, we manually entered each MAC address, which can be boring for a network administrator. However, with the sticky MAC feature, there is no need to manually input every MAC address. Instead, the switch automatically learns and stores them dynamically. When it hits the maximum number of MAC addresses, it stops learning new addresses. Here is the basic configuration of the sticky method with shutdown violation mode:

 sticky command

In the same way, you can configure the restricted and protected modes of the port security. By the way configure the following setting for restrict mode with sticky mac-address:

 restrict command

While below configuration is for protect mode.

 protect command

That was the simple and easy configuration of Switchport security. If you are looking for more such CCNA practical labs, then explore more topics here at the link.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *