Port Security Configuration in Cisco Packet Tracer

Aisyah Aldina

Illustration of a security camera for a guide on port security in Cisco Packet Tracer

Hi everyone, the switch ports in an office are usually wired to network wall sockets. If those ports are left unprotected, anyone can unplug a PC, plug in their own laptop, and get straight onto the office network. Port security on a Cisco switch prevents this by remembering the MAC address of the legitimate device on each port, then shutting the port down when an unknown device is plugged in.

In this article I practice port security in sticky mode in Cisco Packet Tracer 8.2.1, including a simulated intruder laptop and how to recover a port that has been locked. If you have never worked in a switch CLI before, read my guide on Cisco switch configuration in Packet Tracer first.

Download the Packet Tracer lab file
Open with Cisco Packet Tracer 8.2.1 or later · 1 switch, 3 PCs, 1 laptop · Sticky port security already enabled
Download .pkt

The Topology and Cables Used

One switch for the office LAN

Cisco Packet Tracer window showing a port security topology with one switch

The topology this time is simple and has no router, because port security works on the switch. The devices are 1 Cisco 2960-24TT switch, 3 office PCs, and 1 laptop that plays the role of the intruder.

Office LAN box with a switch and three PCs, next to a red box holding the intruder laptop

The teal box is the office LAN on the 192.168.1.0/24 network. The red box holds the intruder laptop with the IP 192.168.1.50. I gave it an IP on the same network on purpose, so it is clear that what blocks it is port security and not a different subnet.

PC0 FastEthernet0   ->  Switch0 FastEthernet0/1   (straight)
PC1 FastEthernet0   ->  Switch0 FastEthernet0/2   (straight)
PC2 FastEthernet0   ->  Switch0 FastEthernet0/3   (straight)
Laptop0             ->  belum tersambung

Every cable is Copper Straight-Through, because a PC and a switch are different kinds of devices. The laptop is not connected yet. The PC IPs are 192.168.1.10, 192.168.1.11, and 192.168.1.12 with the subnet mask 255.255.255.0. You can leave the gateway empty, since all devices are on the same network.

Set the PC0 IP

PC0 marked with a red circle in the port security topology

Click PC0, which I marked with a red circle.

PC0 Desktop tab with IP Configuration and Command Prompt marked

Click the Desktop tab. We will use IP Configuration to set the IP and Command Prompt for the ping tests later.

IP 192.168.1.10 and subnet mask 255.255.255.0 on PC0

Enter 192.168.1.10 as the IPv4 Address and 255.255.255.0 as the Subnet Mask. Repeat this on PC1 with 192.168.1.11, on PC2 with 192.168.1.12, and on Laptop0 with 192.168.1.50.

Configuring Port Security on the Switch

Open the Switch0 CLI

Switch0 marked with a red circle in the topology

Close the PC window, then click Switch0 at the top of the topology.

CLI tab marked in the Switch0 window

In the Switch0 window, click the CLI tab, then press Enter until the Switch> prompt appears.

Enable port security on Fa0/1 to Fa0/3

switchport port-security maximum 1, sticky, and violation shutdown configured on Fa0/1 to Fa0/3
enable
configure terminal
interface range fastEthernet0/1-3
switchport mode access
switchport port-security
switchport port-security maximum 1
switchport port-security mac-address sticky
switchport port-security violation shutdown
end
write memory

Port security can only be enabled on an access port, which is why the switchport mode access line comes first. Maximum 1 means only one MAC address is allowed to use each port.

Mac-address sticky tells the switch to automatically record the first MAC address it sees on that port and save it to the configuration. That way we do not have to type the MAC of every PC by hand. Violation shutdown means that if a different MAC shows up, the port is shut down right away.

Letting the Switch Learn the PC MAC Addresses

Send traffic from the PCs

Successful ping from PC0 to PC1 so the switch learns the MAC addresses

Open the Command Prompt on PC0 and ping PC1 and PC2.

ping 192.168.1.11
ping 192.168.1.12

These pings make all three PCs send packets, so the switch can record the MAC address of each one.

Check the locked MAC addresses

Output of show port-security address with three SecureSticky MAC addresses

Go back to the Switch0 CLI and run the following command.

show port-security address

Each of the three ports now has one MAC address of type SecureSticky. From now on, Fa0/1 only accepts PC0, Fa0/2 only accepts PC1, and Fa0/3 only accepts PC2.

Simulating an Intruder Laptop

Unplug PC0 and plug in the laptop

Intruder laptop marked with a red circle in the topology

In the real world, an intruder unplugs the cable from a PC and plugs it into their own laptop. In Packet Tracer I remove the PC0 cable with the Delete tool, then connect a new straight cable from the laptop’s FastEthernet0 to Fa0/1 on the switch. The laptop sits in the red intruder box.

Warning: Before using the Delete tool, click an empty area first so no device is selected. If Switch0 is still selected, Packet Tracer immediately offers to delete the switch. Click Cancel if you see a prompt like that.

The laptop cannot get onto the network

Ping from the intruder laptop to PC1 returning Request timed out

Open the Command Prompt on Laptop0 and ping PC1.

ping 192.168.1.11

Every reply is Request timed out. As soon as the first frame from the laptop arrives on Fa0/1, the switch sees a MAC address that does not match the locked PC0 MAC, so it shuts the port down.

Topology with port Fa0/1 shown in red after the violation

In the topology, the cable end at Fa0/1 turns into a red triangle, which means the port is down.

Zoom on the switch showing Fa0/1 red while Fa0/2 and Fa0/3 stay green

If you zoom in, you can see that only Fa0/1 is red, while Fa0/2 and Fa0/3 stay green.

Check the violation status

Output of show port-security interface Fa0/1 with the status Secure-shutdown

In the Switch0 CLI, run the following commands.

show port-security interface fastEthernet0/1
show interfaces fastEthernet0/1 status

The Port Status changes to Secure-shutdown, the Security Violation Count is 1, and the Last Source Address shows the MAC address of the intruder laptop. The interface status of Fa0/1 is err-disabled.

Interface Fa0/1 status showing err-disabled

A port in the err-disabled state does not come back up on its own, even after the laptop is unplugged. The admin has to bring it back up manually.

Recovering an Err-disabled Port

Bring the port back up after the real PC is reconnected

shutdown and no shutdown commands bringing Fa0/1 back to connected

Remove the laptop cable, connect the PC0 cable to Fa0/1 again, then type the following commands in the Switch0 CLI.

configure terminal
interface fastEthernet0/1
shutdown
no shutdown
end
show interfaces fastEthernet0/1 status

Running shutdown followed by no shutdown resets the port. The status goes back to connected and PC0 works again, because its MAC address is the one saved by sticky.

Common Problems and How to Fix Them

Command rejected appears when typing switchport port-security

The port is still in dynamic mode. Type switchport mode access on that interface first, then enable port security.

The port goes down again right after no shutdown

The connected device is still not the one whose MAC address was saved. Check the Last Source Address in show port-security interface, and make sure the correct device is plugged in.

The official PC was replaced and needs to use the same port

Remove the old MAC address with the command clear port-security sticky interface fastEthernet0/1, then run shutdown and no shutdown on that port. The switch will learn the MAC address of the new PC.

At this point the switch ports are protected from unknown devices being plugged in at random. In the next article we cover VTP, which is how you automatically share the VLAN list from one switch to the others. If you run into any other error while trying this, just leave a comment below.

Leave a Comment