Configure Port Security on a Cisco Switch in Packet Tracer

Configure Port Security on a Cisco Switch in Packet Tracer
Networking ATN Campus November 05, 2026 44 views

Configure Port Security on a Cisco Switch in Packet Tracer

Learn how to configure Cisco Switch Port Security using Packet Tracer. In this practical lab, you will limit the number of MAC addresses allowed on a switch port, configure static and sticky MAC addresses, test security violations, and understand the different violation modes.


1. What Is Switch Port Security?

Port Security is a Layer 2 security feature available on supported Cisco switches. It helps control which devices can connect through a switch port by limiting the MAC addresses permitted on that interface.

For example, a network administrator can configure a switch port to allow only one approved device. If another device connects and causes a security violation, the switch can take a configured action.

Why Is Port Security Important?

  • Limits unauthorized devices from using a switch port.
  • Controls the number of MAC addresses learned on an interface.
  • Helps protect access-layer switch ports.
  • Provides alerts and counters for security violations.
  • Supports static and dynamically learned secure MAC addresses.

2. What Is a MAC Address?

A MAC (Media Access Control) address is a Layer 2 hardware address used to identify a network interface on a local network.

Example MAC address:

00:1A:2B:3C:4D:5E
    

Switches learn MAC addresses and associate them with the interfaces where devices are connected. Port Security uses this information to decide whether a device is permitted on a protected port.

3. Port Security Violation Modes

Cisco switches commonly support three Port Security violation modes.

ModeAction
ProtectDrops traffic from unauthorized source MAC addresses. It does not generate a syslog notification or increment the violation counter.
RestrictDrops unauthorized traffic and increments the violation counter. It can also generate a syslog or SNMP notification.
ShutdownPlaces the port into an error-disabled state when a violation occurs.

Default violation mode: Shutdown on commonly used Cisco Catalyst access switches.

4. Lab Requirements

  • Cisco Packet Tracer
  • 1 Cisco 2960 switch
  • 3 PCs
  • Ethernet cables

5. Network Topology

       PC1             PC2             PC3
        |               |               |
        |               |               |
      Fa0/1           Fa0/2           Fa0/3
        |               |               |
        +---------------+---------------+
                        |
                     Switch
                      SW1

    PC1 = Authorized device
    PC2 = Unauthorized test device
    PC3 = Another authorized device
    

In this lab, we will configure Port Security on Fa0/1 to allow only one secure MAC address.

6. IP Addressing Table

DeviceIP AddressSubnet Mask
PC1192.168.10.10255.255.255.0
PC2192.168.10.20255.255.255.0
PC3192.168.10.30255.255.255.0

All three PCs are in the same subnet. A router is not required for this basic Layer 2 security lab.

7. Step 1 – Build the Topology

  1. Open Cisco Packet Tracer.
  2. Add one Cisco 2960 switch.
  3. Add three PCs.
  4. Connect PC1 to Fa0/1.
  5. Connect PC2 to Fa0/2.
  6. Connect PC3 to Fa0/3.
  7. Configure the IP addresses on all PCs.

8. Step 2 – Verify MAC Addresses

Before configuring Port Security, identify the MAC addresses of the connected PCs.

On each PC, open Command Prompt and enter:

ipconfig /all
    

Record PC1's MAC address. We will use it to configure a static secure MAC address.

You can also inspect the switch's MAC address table:

show mac address-table
    

9. Step 3 – Configure the Access Port

Open the switch CLI and configure Fa0/1 as an access port.

enable
configure terminal

interface fastEthernet 0/1
switchport mode access
no shutdown
exit
    

Port Security is normally configured on an access port in this lab.

10. Step 4 – Enable Port Security

Enable Port Security on Fa0/1 and limit the port to one secure MAC address.

configure terminal

interface fastEthernet 0/1
switchport port-security
switchport port-security maximum 1
exit
    

Explanation:

  • switchport port-security enables Port Security.
  • maximum 1 allows one secure MAC address on the port.

11. Step 5 – Configure Static MAC Address Security

We can manually configure PC1's MAC address as the only permitted address.

Replace the example MAC address below with the actual MAC address shown on PC1.

configure terminal

interface fastEthernet 0/1
switchport port-security mac-address 00AA.BBCC.DDEE
exit
    

This configures a static secure MAC address. The example address is only a placeholder and must be replaced with PC1's real MAC address.

12. Step 6 – Configure Sticky MAC Learning

Another option is Sticky MAC learning. The switch dynamically learns a MAC address and adds it to the secure address configuration.

If you want to use Sticky learning instead of the manually configured MAC address, remove the static entry and configure:

configure terminal

interface fastEthernet 0/1
no switchport port-security mac-address 00AA.BBCC.DDEE
switchport port-security mac-address sticky
exit
    

Replace the example MAC address with the same address you configured earlier.

Alternatively, if you have not configured a static MAC address, simply enable sticky learning:

interface fastEthernet 0/1
switchport port-security mac-address sticky
    

When PC1 sends traffic through the port, the switch learns its MAC address and adds it to the sticky secure MAC address list.

13. Step 7 – Configure the Violation Mode

Now configure the action the switch should take when an unauthorized MAC address is detected.

Option 1 – Protect Mode

interface fastEthernet 0/1
switchport port-security violation protect
    

Drops unauthorized traffic without a syslog notification or violation counter increment.

Option 2 – Restrict Mode

interface fastEthernet 0/1
switchport port-security violation restrict
    

Drops unauthorized traffic and increments the violation counter. Notifications may also be generated.

Option 3 – Shutdown Mode

interface fastEthernet 0/1
switchport port-security violation shutdown
    

Places the interface into an error-disabled state after a violation.

For this lab, use Shutdown mode to observe the security violation clearly.

14. Step 8 – Verify Port Security

Use the following commands:

show port-security
show port-security interface fastEthernet 0/1
show port-security address
show running-config
    

Check that:

  • Port Security is enabled.
  • The maximum number of secure MAC addresses is 1.
  • The correct MAC address is listed.
  • The violation mode is Shutdown.

15. Step 9 – Test an Unauthorized Device

Now test what happens when another device uses the protected switch port.

  1. Keep PC1 connected to Fa0/1 initially so its MAC address is learned or present as a secure entry.
  2. Disconnect PC1 from Fa0/1.
  3. Connect PC2 to Fa0/1.
  4. Generate traffic from PC2, such as a ping to another PC.
  5. Check the port status on the switch.

With Shutdown mode, the switch should detect the unauthorized MAC address and place the port into an error-disabled state.

show port-security interface fastEthernet 0/1
show interfaces status
    

Important: The violation is detected when traffic with an unauthorized source MAC address is received. Simply connecting a cable may not trigger it immediately.

16. Step 10 – Recover the Port

After a shutdown violation, the interface must be recovered.

First remove the unauthorized device. Then use:

configure terminal
interface fastEthernet 0/1
shutdown
no shutdown
exit
    

If the original secure MAC address remains configured, reconnect the authorized PC. Verify that the interface returns to operation.

17. Common Port Security Troubleshooting

ProblemPossible Solution
Port Security command is rejectedCheck the switch model and configure the interface as an access port.
Port becomes error-disabledCheck the violation counter and remove the unauthorized device before recovering the port.
Authorized PC is blockedVerify the secure MAC address and the interface configuration.
Sticky MAC is not learnedGenerate traffic from the connected device and check the secure address table.
Port remains downCheck the cable, interface state, and error-disabled condition.

18. Frequently Asked Questions

What is Cisco Port Security?

Port Security is a switch feature that limits the MAC addresses allowed to use a switch interface.

What is a Sticky MAC address?

A Sticky MAC address is dynamically learned by the switch and added to the secure MAC address configuration.

What happens in Shutdown mode?

The switch places the interface into an error-disabled state when a Port Security violation occurs.

What is the difference between Protect and Restrict?

Both drop unauthorized traffic. Restrict also increments the violation counter and can generate notifications, while Protect does not.

Does Port Security replace a firewall?

No. Port Security controls MAC addresses at the switch access port. It does not replace firewalls, network segmentation, authentication, or other security measures.

19. Practice Challenge

Complete these tasks to improve your switching skills:

  1. Configure Port Security on Fa0/2.
  2. Allow a maximum of two secure MAC addresses.
  3. Enable Sticky MAC learning.
  4. Configure Restrict violation mode.
  5. Connect an additional device and observe the violation counter.
  6. Compare Protect, Restrict, and Shutdown modes.

Conclusion

In this lab, you learned how to configure Cisco Switch Port Security, limit secure MAC addresses, configure static and Sticky MAC learning, and test the three violation modes.

Port Security is an important access-layer security feature for controlling which devices can connect to a switch.

Learn Networking with ATN Campus

Develop practical networking and security skills with ATN Campus through structured lessons and hands-on labs.

  • CCNA and CCNP Training
  • Network Routing and Switching
  • Subnetting and IP Addressing
  • Network Security and CEH
  • Python for Network Automation
  • Practical Cisco Packet Tracer Labs

???? Want to learn networking? Visit ATN Campus.

???? Learn Networking. ???? Master Routing & Switching. ???? Practice with Real Labs. ???? Prepare for Certifications. ???? Build Your IT Career with ATN Campus.
Document ATN CAMPUS