Port Security
Port Security
Port Security
Note • For complete syntax and usage information for the commands used in this chapter, see these
publications:
http://www.cisco.com/en/US/products/ps11846/prod_command_reference_list.html
• Cisco IOS Release 15.4SY supports only Ethernet interfaces. Cisco IOS Release 15.4SY does not
support any WAN features or commands.
Tip For additional information about Cisco Catalyst 6500 Series Switches (including configuration examples
and troubleshooting information), see the documents listed on this page:
http://www.cisco.com/en/US/products/hw/switches/ps708/tsd_products_support_series_home.html
Participate in the Technical Documentation Ideas forum
• Enter the clear port-security dynamic global configuration command to clear all dynamically
learned secure addresses.
• Port security learns unauthorized MAC addresses with a bit set that causes traffic to them or from
them to be dropped. The show mac address-table command displays the unauthorized MAC
addresses, but does not display the state of the bit. (CSCeb76844)
• To preserve dynamically learned sticky MAC addresses and configure them on a port following a
bootup or a reload and after the dynamically learned sticky MAC addresses have been learned, you
must enter a write memory or copy running-config startup-config command to save them in the
startup-config file.
• Port security supports private VLAN (PVLAN) ports.
• Port security supports IEEE 802.1Q tunnel ports.
• Port security does not support Switch Port Analyzer (SPAN) destination ports.
• Port security supports access and trunking EtherChannel port-channel interfaces.
• You can configure port security and 802.1X port-based authentication on the same port.
• Port security supports nonnegotiating trunks.
– Port security only supports trunks configured with these commands:
switchport
switchport trunk encapsulation
switchport mode trunk
switchport nonegotiate
– If you reconfigure a secure access port as a trunk, port security converts all the sticky and static
secure addresses on that port that were dynamically learned in the access VLAN to sticky or
static secure addresses on the native VLAN of the trunk. 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. Port security removes all addresses learned on VLANs other than the native VLAN.
Note Port security uses the VLAN ID configured with the switchport trunk native vlan
command.
• Take care when you enable port security on the ports connected to the adjacent switches when there
are redundant links running between the switches because port security might error-disable the ports
due to port security violations.
• In Cisco IOS Release 15.1(1)SY2 and later releases, the options starting with the number 6 for the
radius-server attribute command changed from 6, 61, 69 to 6, 61, 66, 67, and 69.
Note After a secure MAC address is configured or learned on one secure port, the sequence of
events that occurs when port security detects that secure MAC address on a different port in
the same VLAN is known as a MAC move violation.
If you enter a write memory or copy running-config startup-config command, then port security with
sticky MAC addresses saves dynamically learned MAC addresses in the startup-config file and the port
does not have to learn addresses from ingress traffic after bootup or a restart.
188919
IP
Because the device is not directly connected to the switch, the switch cannot physically detect a loss of
port link if the device is disconnected. Later Cisco IP phones send a Cisco Discovery Protocol (CDP)
host presence type length value (TLV) to notify the switch of changes in the attached device’s port link
state. The switch recognizes the host presence TLV. Upon receiving a host presence TLV notification of
a link down on the IP phone’s data port, port security removes from the address table all static, sticky,
and dynamically learned MAC addresses. The removed addresses are added again only when the
addresses are learned dynamically or configured.
Caution Because the default number of secure addresses is one and the default violation action is to shut down
the port, configure the maximum number of secure MAC addresses on the port before you enable port
security on a trunk (see “Configuring the Maximum Number of Secure MAC Addresses on a Port”
section on page 85-7).
Command Purpose
Step 1 Router(config)# interface Selects the interface to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport Configures the port as a Layer 2 port.
Step 3 Router(config-if)# switchport trunk encapsulation Configures the encapsulation as 802.1Q.
{isl | dot1q}
Step 4 Router(config-if)# switchport mode trunk Configures the port to trunk unconditionally.
Step 5 Router(config-if)# switchport nonegotiate Configures the trunk not to use DTP.
Step 6 Router(config-if)# switchport port-security Enables port security on the trunk.
Step 7 Router(config-if)# do show port-security Verifies the configuration.
interface type slot/port | include Port Security
This example shows how to configure Gigabit Ethernet port 5/36 as a nonnegotiating trunk and enable
port security:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/36
Router(config-if)# switchport
Router(config-if)# switchport mode trunk
Router(config-if)# switchport nonegotiate
Router(config-if)# switchport port-security
Router(config-if)# do show port-security interface gigabitethernet 5/36 | include Port
Security
Port Security : Enabled
Command Purpose
Step 1 Router(config)# interface Selects the interface to configure.
{type slot/port | port-channel channel_number}
Note The port can be a tunnel port or a PVLAN port.
Step 2 Router(config-if)# switchport Configures the port as a Layer 2 port.
Step 3 Router(config-if)# switchport mode access Configures the port as a Layer 2 access port.
Note A port in the default mode (dynamic desirable)
cannot be configured as a secure port.
Step 4 Router(config-if)# switchport port-security Enables port security on the port.
Step 5 Router(config-if)# do show port-security Verifies the configuration.
interface type slot/port | include Port Security
This example shows how to enable port security on Gigabit Ethernet port 5/12:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/12
Router(config-if)# switchport
Router(config-if)# switchport mode access
Router(config-if)# switchport port-security
Router(config-if)# do show port-security interface gigabitethernet 5/12 | include Port Security
Port Security : Enabled
Command Purpose
Step 1 Router(config)# interface Selects the LAN port to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport port-security (Optional) Sets the violation mode and the action to be
violation {protect | restrict | shutdown} taken when a security violation is detected.
Step 3 Router(config-if)# do show port-security Verifies the configuration. The values for violation_mode
interface type slot/port | include violation_mode are protect, restrict, or shutdown.
• protect—The PFC drops packets with unknown source addresses until you remove a sufficient
number of secure MAC addresses to drop below the maximum value.
• restrict—The PFC drops packets with unknown source addresses until you remove a sufficient
number of secure MAC addresses to drop below the maximum value and causes the security
violation counter to increment.
• shutdown—Puts the interface into the error-disabled state immediately and sends an SNMP trap
notification.
Note To bring a secure port out of the error-disabled state, enter the errdisable recovery cause
violation_mode global configuration command, or you can manually reenable it by entering the
shutdown and no shut down interface configuration commands.
This example shows how to configure the protect security violation mode on Gigabit Ethernet port 5/12:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/12
Router(config-if)# switchport port-security violation protect
Router(config-if)# do show port-security interface gigabitethernet 5/12 | include Protect
Violation Mode : Protect
This example shows how to configure the restrict security violation mode on Gigabit Ethernet port 5/12:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/12
Router(config-if)# switchport port-security violation restrict
Router(config-if)# do show port-security interface gigabitethernet 5/12 | include Restrict
Violation Mode : Restrict
Command Purpose
Step 1 Router(config)# interface Selects the interface to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport port-security Sets the maximum number of secure MAC addresses for
maximum number_of_addresses vlan {vlan_ID | the port (default is 1).
vlan_range}
Note Per-VLAN configuration is supported only on
trunks.
– You can enter a comma-separated list of VLAN numbers and dash-separated pairs of VLAN
numbers.
This example shows how to configure a maximum of 64 secure MAC addresses on Gigabit Ethernet
port 5/12:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/12
Router(config-if)# switchport port-security maximum 64
Router(config-if)# do show port-security interface gigabitethernet 5/12 | include Maximum
Maximum MAC Addresses : 64
Command Purpose
Step 1 Router(config)# interface Selects the interface to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport port-security Enables port security with sticky MAC addresses on a
mac-address sticky port.
Command Purpose
Step 1 Router(config)# interface Selects the LAN port to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport port-security Configures a static MAC address as secure on the port.
mac-address sticky mac_address [vlan vlan_ID]
Note Per-VLAN configuration is supported only on
trunks.
Step 3 Router(config-if)# end Exits configuration mode.
• You can configure sticky secure MAC addresses if port security with sticky MAC addresses is
enabled (see the “Enabling Port Security with Sticky MAC Addresses on a Port” section on
page 85-8).
• The maximum number of secure MAC addresses on the port, configured with the switchport
port-security maximum command, defines how many secure MAC addresses you can configure.
• If you configure fewer secure MAC addresses than the maximum, the remaining MAC addresses are
learned dynamically.
• Port security is supported on trunks.
– On a trunk, you can configure a static secure MAC address in a VLAN.
– On a trunk, if you do not configure a VLAN for a static secure MAC address, it is secure in the
VLAN configured with the switchport trunk native vlan command.
This example shows how to configure a MAC address 1000.2000.3000 as secure on Gigabit Ethernet port
5/12 and verify the configuration:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/12
Router(config-if)# switchport port-security mac-address 1000.2000.3000
Router(config-if)# end
Router# show port-security address
Secure Mac Address Table
------------------------------------------------------------
Note • Static secure MAC addresses and sticky secure MAC addresses do not age out.
• When the aging type is configured with the absolute keyword, all the dynamically learned secure
addresses age out when the aging time expires. When the aging type is configured with the
inactivity keyword, the aging time defines the period of inactivity after which all the dynamically
learned secure addresses age out.
Command Purpose
Step 1 Router(config)# interface Selects the LAN port to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport port-security aging Configures the secure MAC address aging type on the
type {absolute | inactivity} port (default is absolute).
This example shows how to set the aging type to inactivity on Gigabit Ethernet port 5/12:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/12
Router(config-if)# switchport port-security aging type inactivity
Router(config-if)# do show port-security interface gigabitethernet 5/12 | include Type
Aging Type : Inactivity
Command Purpose
Step 1 Router(config)# interface Selects the interface to configure.
{type slot/port | port-channel channel_number}
Step 2 Router(config-if)# switchport port-security aging Configures the secure MAC address aging time on the
time aging_time port. The aging_time range is 1 to 1440 minutes (default
is 0).
This example shows how to configure 2 hours (120 minutes) as the secure MAC address aging time on
Gigabit Ethernet port 5/1:
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)# interface gigabitethernet 5/1
Router(config-if)# switchport port-security aging time 120
Command Purpose
Router# show port-security [interface {{vlan vlan_ID} Displays port security settings for the switch or for the
| {type slot/port}}] [address] specified interface.
Gi5/1 11 11 0 Shutdown
Gi5/5 15 5 0 Restrict
Gi5/11 5 4 0 Protect
----------------------------------------------------------------------------
This example displays output from the show port-security command for a specified interface:
Router# show port-security interface gigabitethernet 5/1
Port Security: Enabled
Port status: SecureUp
Violation mode: Shutdown
Maximum MAC Addresses: 11
Total MAC Addresses: 11
Configured MAC Addresses: 3
Aging time: 20 mins
Aging type: Inactivity
SecureStatic address aging: Enabled
Security Violation count: 0
This example displays the output from the show port-security address privileged EXEC command:
Router# show port-security address
Secure Mac Address Table
-------------------------------------------------------------------
Vlan Mac Address Type Ports Remaining Age
(mins)
Tip For additional information about Cisco Catalyst 6500 Series Switches (including configuration examples
and troubleshooting information), see the documents listed on this page:
http://www.cisco.com/en/US/products/hw/switches/ps708/tsd_products_support_series_home.html
Participate in the Technical Documentation Ideas forum