How to Enable Port Security on a Switch? (4 Simple Steps!)

Ensuring security for the devices connected to your network is very important. Especially in situations where you use a network switch, it is a must to restrict the users connecting to your network through a port. But how can you enable port security in a switch?

In this article, we shall be discussing the method to enable port security in a switch and the potential benefits of enabling it.

How to Enable Port Security on a Switch (4 Simple Steps!)

How to Enable Port Security on a Switch?

You can enable the port security in your network switch with the help of the following steps:

  • Accessing the switch
  • Interface Identification
  • Enabling port security
  • Applying the configuration

Accessing the Switch

In this step, you must first access the switch by connecting it to a computer or remote management interface. This will allow you to configure the switch settings like enabling port security.

Mostly, your switch will already be connected to a main computer system, and you just need to access it with relevant credentials (if using any).

Interface Identification

Once you have accessed the switch, you must now identify which port or interface you are going to enable security. Every port has an identifier that is unique to it. They can be named FastEthernet0/1 or GigabitEthernet0/1.

After you identify the port, you must enter into the configuration mode. This can be done by the following procedure:

  • Open the Command Line Interface of your Switch
  • Go to the specific interface by typing the command “configure terminal” followed by the [interface-id]. Interface ID denotes the identifier with which the port is being known and you will be enabling security in this port.

Enabling port security

Once you enter the configuration mode for the specific port, you must now follow these steps to enable port security:

  • Setting Maximum Allowed MAC addresses
  • Specify Action for Security Violation
  • Additional Configurations (if required)

Setting Maximum Allowed MAC addresses

In the port configuration terminal, enter the command “switchport port-security”. This will enable port security features for the particular interface. But you have to specify the maximum number of MAC addresses (i.e., devices) that can be connected to the port.

Therefore, to restrict the device connectivity, enter the following command:

switchport port-security maximum [max-count]

In place of the max-count, you must enter the desired number of devices you want to allow for connectivity in that particular port.

After you enable this security feature, only the specified number of devices can be connected to that particular port in your network switch.

Specify Action for Security Violation

Another security feature you can enable in the port security is the actions to be taken during violations. Whenever the port is being used without authorization, you can specify some actions to be taken. They are:

  • Protect – Drops packets from unauthorized MAC addresses without any notification
  • Restrict – Drops packets from unauthorized MAC addresses and generates a log message
  • Shutdown – Disables the interface where the violation occurs

You can either protect the port by dropping the data packets sent through it and there will not be any notification sent to the device connected. Or you can restrict the device by dropping the data packets and giving out a log message. Finally, you can completely shutdown or disable the port when a violation occurs.

According to your necessity, you can enable any one of the actions when a violation occurs. To enable these actions, type the following command:

switchport port-security violation [action]

Replace [action] with protect, restrict, or shutdown actions as per your requirements. Most of the people choose “restrict” or “shutdown” actions.

Additional Configurations

Apart from these configs, you can enhance port security by setting an aging time to dynamically known MAC addresses or you can specify a MAC address that should be allowed for a specific time with the help of the following command:

switchport port-security aging time [seconds] and switchport port-security mac-address [mac-address]

Applying the Configuration

Once you have completed setting up all the necessary security features, you can simply exit the interface by typing “exit” and then save the config by entering “write memory” or copy running-config startup-config

This will save the settings and ensures these port security settings work even after rebooting the system.

These are the steps you must follow to enable port security in your network switch. If you enable these settings, you have several benefits, and let us look at them now.

Read: Are unmanaged switches slower?

Benefits of Enabling Port Security

When you enable port security, you can get the following benefits from it:

Prevention from Unauthorized devices

Enabling port security will prevent unauthorized devices from accessing your network. Even if they try to access, the port will shut down or send a restricted use warning if you had enabled port security.

MAC address filtering

When you enable port security, you can specify the number of MAC addresses or even the specific MAC address to be allowed to access the port. You can configure the switch port security with any of the commands discussed above and enable only the required MAC addresses for access.

Read: Can I use a PoE switch as a regular switch?

Prevention from Cyberattacks

If your network switch port is safe and secure, no cyber-attacks can be performed through it. Whenever an intruder device tries to access the port, it will simply shut down or protect itself. So, you can prevent any kind of attacks from intruders and prevent your data.

Better Traceability

When you have restricted access to the port, you can trace the MAC addresses accessing the port using the log message. This will allow network administrators to identify and troubleshoot the interfaces easily.

Minimal Insider Threats

Insider threats that compromise network security can be avoided by enabling port security features. You can prevent unauthorized internal access and also provides complete control over network access.

These are the major benefits of enabling port security and you can follow the above-mentioned steps to perform it successfully.

Read: Does a network switch split speed?


Port security for a network switch is integral for the safety and security of your network. Enable the features properly with the help of these guidelines and prevent the network from threats and attacks.

Scroll to Top