Achievable logoAchievable logo
CCNA
Sign in
Sign up
Purchase
Textbook
Practice exams
Support
How it works
Exam catalog
Mountain with a flag at the peak
Textbook
Introduction
1. Introduction to networking
2. Administering Ethernet LANs
3. IP connectivity
4. Network services
5. IPv6
6. Wireless networking
7. Network management and administering network devices
8. Network security fundamentals
8.1 Fundamental network security concepts
8.2 Securing access to Cisco network devices
8.3 Firewalls and Intrusion Prevention Systems (IPS)
8.4 Virtual Private Networks (VPNs)
8.5 Layer 2 security features
8.5.1 Port security
8.5.2 DHCP Snooping and Dynamic ARP Inspection (DAI)
9. Network automation and programmability
Wrapping up
Achievable logoAchievable logo
8.5.1 Port security
Achievable CCNA
8. Network security fundamentals
8.5. Layer 2 security features
Our CCNA course is currently in development and is a work-in-progress.

Port security

6 min read
Font
Discuss
Share
Feedback

As a foundational element of network defense, Layer 2 security helps control who can access your network. One of the most important Layer 2 features is port security, which lets you control which devices are allowed to connect to specific switchports. This chapter covers the fundamentals of Port Security, including how it works, how to configure it, and how to verify it.

Understanding port security fundamentals

Port Security is a switch feature that lets you restrict access to a switchport based on the MAC address of the connected device. The main purpose is to prevent unauthorized devices from gaining network access by plugging into an unused or compromised switchport.

If an unauthorized device sends traffic, port security can respond in different ways - from dropping specific Ethernet frames to disabling the port entirely.

Image

Image Title - Port Security feature in action

Port security is built around MAC addresses. It inspects the Source MAC Address field of incoming Ethernet frames. Each switchport configured with port security keeps:

  • A list of allowed MAC addresses
  • A maximum number of MAC addresses that are allowed on that port

A security violation occurs when:

  • A frame arrives with a source MAC address that isn’t allowed, or
  • A new MAC address is learned and it would exceed the configured maximum

Key operational aspects of Port Security include:

  • Per-Port Configuration: Port Security settings are applied individually to each switch interface, so you can control access port by port.
  • Maximum MAC Addresses: Each port can be configured to allow a specific number of unique source MAC addresses. The default is typically one.
  • MAC Address Learning: MAC addresses can be statically configured, dynamically learned, or “sticky learned.”
  • Violation Actions: When a security violation occurs, the switch takes a predefined action, which can vary in severity.

Configuring port security

Configuring port security is done per interface. Before you enable port security, the interface must be configured as either an access port or a trunk port.

The Dynamic Trunking Protocol (DTP) configuration (not discussed here because it’s outside the scope of the CCNA 200-301 v1.1 exam) is not compatible with Port Security.

Here’s a breakdown of the configuration commands:

  1. Enable Port Security:

Enter interface configuration mode for the switchport (for example, interface gigabitethernet0/1) and enable port security:

Switch

configure terminal\

Switch(config)

interface gigabitethernet0/1\

Switch(config-if)

switchport port-security

This command activates port security on the interface with default settings: (maximum 1 MAC address, shutdown violation mode).

  1. Configure Maximum MAC Addresses (Optional):

Switch(config-if)

switchport port-security maximum [number]

Use this to override the default maximum of one MAC address. For example, a port connected to an IP phone that also has a PC connected would need a maximum of at least two.

  1. Define Static MAC Addresses (Optional):

Switch(config-if)

switchport port-security mac-address [mac-address]

This command lets you explicitly specify an allowed MAC address. You can repeat this command for multiple static entries, up to the configured maximum.

  1. Enable Sticky MAC Address Learning (Optional):

Switch(config-if)

switchport port-security mac-address sticky

Sticky learning is a convenient feature where the switch dynamically learns the MAC addresses of connected devices and then automatically converts them into static entries in the running configuration.

This reduces manual configuration effort while still giving you the benefits of static MAC addresses.

Remember to save the running configuration (copy running-config startup-config) to preserve these learned sticky MAC addresses across reloads.

Image

Image Title - Screenshot of Sticky MAC address learning in the running config

  1. Set Violation Mode (Optional):

Switch(config-if)

switchport port-security violation [protect | restrict | shutdown]

This command defines the action the switch will take when a security violation occurs. We will explore these modes in detail below.

Port security violation modes

When a security violation occurs, port security can react in one of three ways:

  1. Shutdown (Default Mode): This is the most aggressive mode. When a violation occurs, the switch immediately disables the port, placing it into an “err-disabled” state. The port stops forwarding all traffic, both legitimate and unauthorized. The switch will also generate Syslog messages.

    To recover a port from an err-disabled state, a network administrator must manually shut down and then re-enable the interface (shutdown followed by no shutdown).

    Switch(config-if)#shutdown
    Switch(config-if)#no shutdown

    We mentioned the err-disabled state briefly in Chapter 2.4.3 Rapid PVST+ and advanced STP features under the BPDU Guard section.

  2. Protect Mode: In Protect mode, when a violation occurs, the switch discards the offending frames. The port remains operational and continues to forward traffic from authorized devices.

    Protect mode provides minimal feedback:

    • It does not generate Syslog messages
    • It does not send SNMP traps
    • It does not increment a violation counter

    This can make troubleshooting harder because the port appears “up” but silently drops unauthorized traffic.

  3. Restrict Mode: Restrict mode balances Protect and Shutdown. Like Protect mode, it discards offending frames and keeps the port operational for authorized traffic. Unlike Protect mode, Restrict mode:

    • Generates syslog messages
    • Sends SNMP traps
    • Increments a security violation counter

    This gives you visibility into unauthorized access attempts without disabling the port.

Verifying port security

After configuring Port Security, verify that it’s operating as intended. Several show commands are commonly used for verification:

  • show port-security interface [slot/number] This command provides detailed information about port security on a specific interface, including its enabled status, violation mode, maximum MAC addresses, current MAC addresses that were learned, and any security violation counts. It also shows the port’s security status (e.g., Secure-up, Secure-shutdown).

    Image

    Image Title - Screenshot of a sample output on a port configured with Port Security

  • show port-security: This command provides a summary of port security status across all interfaces where it is enabled, including the interface, maximum allowed addresses, current addresses, violation count, and configured action.

    Image

    Image Title - Screenshot of a sample output when the “show port-security” command is executed

  • show interfaces status err-disabled: Useful for checking whether an interface has entered an err-disabled state due to a port security violation.

  • show mac address-table secure: When port security is enabled, MAC addresses learned on that port are no longer shown as “dynamic” in show mac address-table dynamic output. Instead, they are treated as secure entries. This command displays MAC addresses that have been secured by port security.

  • show mac address-table static: This command lists statically configured MAC addresses, including MAC addresses manually defined with switchport port-security mac-address and any sticky-learned MAC addresses that were saved to the startup configuration.

Port security fundamentals

  • Restricts switchport access based on MAC addresses
  • Maintains allowed MAC address list and maximum per port
  • Security violation triggers:
    • Unknown MAC address detected
    • Exceeding maximum allowed MAC addresses

Key operational aspects

  • Per-port configuration - settings applied individually
  • Maximum MAC addresses - default is one, configurable
  • MAC address learning:
    • Static, dynamic, or sticky
  • Violation actions - predefined response to violations

Configuring port security

  • Interface must be access or trunk port (not dynamic)
  • Enable with switchport port-security
  • Optional configurations:
    • Set maximum MAC addresses: switchport port-security maximum [number]
    • Define static MAC addresses: switchport port-security mac-address [mac-address]
    • Enable sticky learning: switchport port-security mac-address sticky
      • Sticky MACs become static entries in running config
      • Save config to retain sticky MACs after reload
    • Set violation mode: switchport port-security violation [protect | restrict | shutdown]

Port security violation modes

  • Shutdown (default): disables port (err-disabled), requires manual recovery
  • Protect: drops unauthorized frames, no alerts/logs, port stays up
  • Restrict: drops unauthorized frames, generates syslog/SNMP, increments violation counter

Verifying port security

  • show port-security interface [slot/number]: details per interface - status, mode, MACs, violations
  • show port-security: summary for all enabled interfaces
  • show interfaces status err-disabled: checks for ports in err-disabled state
  • show mac address-table secure: lists secure (port security) MAC addresses
  • show mac address-table static: lists static and sticky-learned MAC addresses

Sign up for free to take 5 quiz questions on this topic

Previous
Next  | 8.5.2 DHCP Snooping and Dynamic ARP Inspection (DAI)
All rights reserved ©2016 - 2026 Achievable, Inc.

Port security

As a foundational element of network defense, Layer 2 security helps control who can access your network. One of the most important Layer 2 features is port security, which lets you control which devices are allowed to connect to specific switchports. This chapter covers the fundamentals of Port Security, including how it works, how to configure it, and how to verify it.

Understanding port security fundamentals

Port Security is a switch feature that lets you restrict access to a switchport based on the MAC address of the connected device. The main purpose is to prevent unauthorized devices from gaining network access by plugging into an unused or compromised switchport.

If an unauthorized device sends traffic, port security can respond in different ways - from dropping specific Ethernet frames to disabling the port entirely.

Image

Image Title - Port Security feature in action

Port security is built around MAC addresses. It inspects the Source MAC Address field of incoming Ethernet frames. Each switchport configured with port security keeps:

  • A list of allowed MAC addresses
  • A maximum number of MAC addresses that are allowed on that port

A security violation occurs when:

  • A frame arrives with a source MAC address that isn’t allowed, or
  • A new MAC address is learned and it would exceed the configured maximum

Key operational aspects of Port Security include:

  • Per-Port Configuration: Port Security settings are applied individually to each switch interface, so you can control access port by port.
  • Maximum MAC Addresses: Each port can be configured to allow a specific number of unique source MAC addresses. The default is typically one.
  • MAC Address Learning: MAC addresses can be statically configured, dynamically learned, or “sticky learned.”
  • Violation Actions: When a security violation occurs, the switch takes a predefined action, which can vary in severity.

Configuring port security

Configuring port security is done per interface. Before you enable port security, the interface must be configured as either an access port or a trunk port.

The Dynamic Trunking Protocol (DTP) configuration (not discussed here because it’s outside the scope of the CCNA 200-301 v1.1 exam) is not compatible with Port Security.

Here’s a breakdown of the configuration commands:

  1. Enable Port Security:

Enter interface configuration mode for the switchport (for example, {`interface gigabitethernet0/1`}) and enable port security:

Switch

configure terminal\

Switch(config)

interface gigabitethernet0/1\

Switch(config-if)

switchport port-security

This command activates port security on the interface with default settings: (maximum 1 MAC address, shutdown violation mode).

  1. Configure Maximum MAC Addresses (Optional):

Switch(config-if)

switchport port-security maximum [number]

Use this to override the default maximum of one MAC address. For example, a port connected to an IP phone that also has a PC connected would need a maximum of at least two.

  1. Define Static MAC Addresses (Optional):

Switch(config-if)

switchport port-security mac-address [mac-address]

This command lets you explicitly specify an allowed MAC address. You can repeat this command for multiple static entries, up to the configured maximum.

  1. Enable Sticky MAC Address Learning (Optional):

Switch(config-if)

switchport port-security mac-address sticky

Sticky learning is a convenient feature where the switch dynamically learns the MAC addresses of connected devices and then automatically converts them into static entries in the running configuration.

This reduces manual configuration effort while still giving you the benefits of static MAC addresses.

Remember to save the running configuration ({`copy running-config startup-config`}) to preserve these learned sticky MAC addresses across reloads.

Image

Image Title - Screenshot of Sticky MAC address learning in the running config

  1. Set Violation Mode (Optional):

Switch(config-if)

switchport port-security violation [protect | restrict | shutdown]

This command defines the action the switch will take when a security violation occurs. We will explore these modes in detail below.

Port security violation modes

When a security violation occurs, port security can react in one of three ways:

  1. Shutdown (Default Mode): This is the most aggressive mode. When a violation occurs, the switch immediately disables the port, placing it into an “err-disabled” state. The port stops forwarding all traffic, both legitimate and unauthorized. The switch will also generate Syslog messages.

    To recover a port from an err-disabled state, a network administrator must manually shut down and then re-enable the interface (shutdown followed by no shutdown).

    Switch(config-if)#shutdown
    Switch(config-if)#no shutdown

    We mentioned the err-disabled state briefly in Chapter 2.4.3 Rapid PVST+ and advanced STP features under the BPDU Guard section.

  2. Protect Mode: In Protect mode, when a violation occurs, the switch discards the offending frames. The port remains operational and continues to forward traffic from authorized devices.

    Protect mode provides minimal feedback:

    • It does not generate Syslog messages
    • It does not send SNMP traps
    • It does not increment a violation counter

    This can make troubleshooting harder because the port appears “up” but silently drops unauthorized traffic.

  3. Restrict Mode: Restrict mode balances Protect and Shutdown. Like Protect mode, it discards offending frames and keeps the port operational for authorized traffic. Unlike Protect mode, Restrict mode:

    • Generates syslog messages
    • Sends SNMP traps
    • Increments a security violation counter

    This gives you visibility into unauthorized access attempts without disabling the port.

Verifying port security

After configuring Port Security, verify that it’s operating as intended. Several show commands are commonly used for verification:

  • show port-security interface [slot/number] This command provides detailed information about port security on a specific interface, including its enabled status, violation mode, maximum MAC addresses, current MAC addresses that were learned, and any security violation counts. It also shows the port’s security status (e.g., Secure-up, Secure-shutdown).

    Image

    Image Title - Screenshot of a sample output on a port configured with Port Security

  • show port-security: This command provides a summary of port security status across all interfaces where it is enabled, including the interface, maximum allowed addresses, current addresses, violation count, and configured action.

    Image

    Image Title - Screenshot of a sample output when the “show port-security” command is executed

  • show interfaces status err-disabled: Useful for checking whether an interface has entered an err-disabled state due to a port security violation.

  • show mac address-table secure: When port security is enabled, MAC addresses learned on that port are no longer shown as “dynamic” in show mac address-table dynamic output. Instead, they are treated as secure entries. This command displays MAC addresses that have been secured by port security.

  • show mac address-table static: This command lists statically configured MAC addresses, including MAC addresses manually defined with {`switchport port-security mac-address`} and any sticky-learned MAC addresses that were saved to the startup configuration.

Key points

Port security fundamentals

  • Restricts switchport access based on MAC addresses
  • Maintains allowed MAC address list and maximum per port
  • Security violation triggers:
    • Unknown MAC address detected
    • Exceeding maximum allowed MAC addresses

Key operational aspects

  • Per-port configuration - settings applied individually
  • Maximum MAC addresses - default is one, configurable
  • MAC address learning:
    • Static, dynamic, or sticky
  • Violation actions - predefined response to violations

Configuring port security

  • Interface must be access or trunk port (not dynamic)
  • Enable with {`switchport port-security`}
  • Optional configurations:
    • Set maximum MAC addresses: {`switchport port-security maximum [number]`}
    • Define static MAC addresses: {`switchport port-security mac-address [mac-address]`}
    • Enable sticky learning: {`switchport port-security mac-address sticky`}
      • Sticky MACs become static entries in running config
      • Save config to retain sticky MACs after reload
    • Set violation mode: {`switchport port-security violation [protect | restrict | shutdown]`}

Port security violation modes

  • Shutdown (default): disables port (err-disabled), requires manual recovery
  • Protect: drops unauthorized frames, no alerts/logs, port stays up
  • Restrict: drops unauthorized frames, generates syslog/SNMP, increments violation counter

Verifying port security

  • {`show port-security interface [slot/number]`}: details per interface - status, mode, MACs, violations
  • {`show port-security`}: summary for all enabled interfaces
  • {`show interfaces status err-disabled`}: checks for ports in err-disabled state
  • {`show mac address-table secure`}: lists secure (port security) MAC addresses
  • {`show mac address-table static`}: lists static and sticky-learned MAC addresses

More from Layer 2 security features

  • DHCP Snooping and Dynamic ARP Inspection (DAI)