How to configure port-security on Cisco Switch (2024)

By default, there is no limit to the number of MAC addresses a switch can learn on an interface, and all MAC addresses are allowed. If we want, we can change this behavior with port security. Let’s take a look at the following situation:




How to configure port-security on Cisco Switch (1)

In the topology above, someone connected a cheap (unmanaged) switch that they brought from home to the FastEthernet 0/1 interface of our Cisco switch. Sometimes people like to bring an extra switch from home to the office. As a result, our Cisco switch will learn the MAC address of H1 and H2 on its FastEthernet 0/1 interface.

Of course, we don’t want people to bring their own switches and connect them to our network, so we want to prevent this from happening. This is how we can do it:

Switch(config)#interface fa0/1Switch(config-if)#switchport port-securitySwitch(config-if)#switchport port-security maximum 1

Use the switchport port-security command to enable port security. I have configured port security, so only one MAC address is allowed. Once the switch sees another MAC address on the interface, it will be in violation, and something will happen. I’ll show you what happens in a bit…

Besides setting a maximum on the number of MAC addresses, we can also use port security to filter MAC addresses. You can use this to only allow specific MAC addresses. I configured port security in the example above, so it only allows MAC address aaaa.bbbb.cccc. This is not the MAC address of my computer, so it’s perfect for demonstrating a violation.

Switch(config)#interface fa0/1Switch(config-if)#switchport port-security mac-address aaaa.bbbb.cccc

Use the switchport port-security mac-address command to define the MAC address that you want to allow. Now we’ll generate some traffic to cause a violation:

C:\Documents and Settings\H1>ping 1.2.3.4

I’m pinging to some bogus IP address…there is nothing with IP address 1.2.3.4; I just want to generate some traffic. Here’s what you will see:

SwitchA#%PM-4-ERR_DISABLE: psecure-violation error detected on Fa0/1, putting Fa0/1 in err-disable state%PORT_SECURITY-2-PSECURE_VIOLATION: Security violation occurred, caused by MAC address 0090.cc0e.5023 on port FastEthernet0/1.%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to down

We have a security violation, and as a result, the port goes in err-disable state. As you can see, it is now down. Let’s take a closer look at port security:

Switch#show port-security interface fa0/1Port Security : EnabledPort Status : Secure-shutdownViolation Mode : ShutdownAging Time : 0 minsAging Type : AbsoluteSecureStatic Address Aging : DisabledMaximum MAC Addresses : 1Total MAC Addresses : 1Configured MAC Addresses : 1Sticky MAC Addresses : 0Last Source Address:Vlan : 0090.cc0e.5023:1Security Violation Count : 1

Here is a useful command to check your port security configuration. Use show port-security interface to see the port security details per interface. You can see the violation mode is shutdown and that the last violation was caused by MAC address 0090.cc0e.5023 (H1).

Switch#show interfaces fa0/1FastEthernet0/1 is down, line protocol is down (err-disabled)

Shutting the interface after a security violation is a good idea (security-wise), but the problem is that the interface will stay in err-disable state. This probably means another call to the helpdesk and you bringing the interface back to the land of the living! Let’s activate it again:

Switch(config)#interface fa0/1Switch(config-if)#shutdownSwitch(config-if)#no shutdown

To get the interface out of the err-disable state, you need to type “shutdown” followed by “no shutdown.” Only typing “no shutdown” is not enough!

It might be easier if the interface could recover itself after a certain time. You can enable this with the following command:

How to configure port-security on Cisco Switch (2024)

FAQs

How to enable port security on Cisco? ›

1. Configure the switch port as an access port using the “switchport mode access” command. 2. Activate port security on the switch port with the “switchport port-security” command.

What are the steps involved to configure port security? ›

To configure port security, three steps are required:
  1. define the interface as an access interface by using the switchport mode access interface subcommand.
  2. enable port security by using the switchport port-security interface subcommand.

How do I know if port security is enabled Cisco? ›

Here is a useful command to check your port security configuration. Use show port-security interface to see the port security details per interface. You can see the violation mode is shutdown and that the last violation was caused by MAC address 0090. cc0e.

Why do we configure port security on a switch? ›

The main reason to use port security in a switch is to stop or prevent unauthorized users to access the LAN.

How does port security work on Cisco switch? ›

Port security removes all secure addresses on the voice VLAN of the access port. – If you reconfigure a secure trunk as an access port, port security converts all sticky and static addresses learned on the native VLAN to addresses learned on the access VLAN of the access port.

What is Cisco Switchport port security? ›

The switchport security feature offers the ability to configure a switchport so that traffic can be limited to only a specific configured MAC address or list of MAC addresses.

What are the 6 commands related to port security? ›

Related commands: port-security enable, port-security port-mode, port-security ntk-mode, port-security intrusion-mode, port-security max-mac-count, port-security authorization ignore, port-security oui, and port-security trap.

How to protect a switch port? ›

Secure Unused Ports: Disable unused switch ports to prevent unauthorized devices from connecting to the network. By deactivating these ports, organizations reduce the potential attack surface and minimize the risk of unauthorized access.

What are the three types of port security? ›

You can configure the port for one of three violation modes: protect, restrict, or shutdown.

How to check port configuration in Cisco? ›

To display the serial (console) port configuration, use the show serial command. This command has no arguments or keywords. The default values for Baud rate, Character, Flow Control, Stop Bits, Parity type of the port configuration are 9600, 8, off, 1, none.

How to clear port security violation on Cisco switch? ›

You can clear the counter by going into configure terminal, the interface, and flipping port security off then on. this will clear the counters without having to do a restart.

Which command will enable port security? ›

switchport port security example
CommandDescription
Switch(config-if)#switchport port-securityEnable port security feature on this port
Switch(config-if)#switchport port-security maximum 1Set limit for hosts that can be associated with interface. Default value is 1. Skip this command to use default value.
6 more rows
Nov 30, 2023

What is the default port security setting on a switch port? ›

Default Port Security Configuration
FeatureDefault Setting
Port securityDisabled on a port
Maximum number of secure MAC addresses1
Violation modeShutdown. The port shuts down when the maximum number of secure MAC addresses is exceeded, and an SNMP trap notification is sent.
AgingDisabled
3 more rows
Mar 21, 2015

How do I configure a switch port? ›

Steps to configure Cisco switch using CLI
  1. Switch# configure terminal. Switch(config)# ...
  2. Switch(config)#hostname <switch_name> ...
  3. Switch(config)# ip default-gateway <IP-address> ...
  4. Switch(config)# line aux 0. ...
  5. Switch(config)# ip route <dest_IP_address> <mask> ...
  6. Switch(config)#interface fastethernet 0/1. ...
  7. Switch(config-if)#duplex full.

How do I enable port access? ›

How to open a port on the firewall
  1. Click on Start then on Control Panel.
  2. Click on Windows Firewall and then click on Advanced Settings.
  3. Right click on Inbound Rules then on New Rule:
  4. Select Port and click on Next:
  5. Enter a specific local port (e.g. 8080) and click on Next:
  6. Click on Next:
  7. Name the rule and click on Finish:
Jun 16, 2023

Why is port error disabled Cisco? ›

The Errdisable error disable feature was designed to inform the administrator when there is a port problem or error. The reasons a catalyst switch can go into Errdisable mode and shutdown a port are many and include: Duplex Mismatch. Loopback Error.

What is the switch command to issue port security on a port? ›

switchport port security example
CommandDescription
Switch(config-if)#switchport port-securityEnable port security feature on this port
Switch(config-if)#switchport port-security maximum 1Set limit for hosts that can be associated with interface. Default value is 1. Skip this command to use default value.
6 more rows
Nov 30, 2023

How to enable sticky port security? ›

To enable sticky learning, enter the switchport port-security mac-address sticky command. When you enter this command, the interface converts all the dynamic secure MAC addresses, including those that were dynamically learned before sticky learning was enabled, to sticky secure MAC addresses.

Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 5392

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.