Layer 2 Switch Security

Layer-2 Switch Security

1. What is Layer-2 Switch Security?

Layer-2 Switch Security refers to a set of security features and policies implemented on a Layer-2 network switch to Protect the LAN from Unauthorized Access, Malicious Devices, and Network Attacks. It operates mainly at the Data Link Layer (Layer 2) of the OSI Model and uses MAC addresses, VLANs, switch ports, and Ethernet frames to control network access.

Example: Suppose an office has 50 computers connected to a managed Layer-2 switch. An unauthorized person disconnects an employee’s computer and connects a personal laptop to the same network cable. Layer-2 security features can detect and block this unauthorized device from accessing the network.

2. Why is Layer-2 Switch Security Needed?

Layer-2 security is required to prevent unauthorized devices from connecting to the network and to protect internal LAN communication. Without proper security, attackers can connect rogue devices, perform MAC spoofing, ARP spoofing, DHCP attacks, and generate excessive broadcast traffic.

Example: In a corporate office, an unauthorized person connects a personal laptop to an unused switch port. Without security policies, the laptop may receive network access and communicate with internal systems. Port Security and 802.1X Authentication help prevent this situation.

3. How Does Layer-2 Switch Security Work?

Layer-2 security works by applying security policies to individual switch ports and monitoring network traffic. When a device connects to a switch port, the switch can check its MAC address, authenticate the user or device, verify DHCP information, and inspect ARP packets.

Example: An administrator configures a switch port to allow only one authorized MAC address. When the approved computer connects, communication is allowed. If another computer connects to the same port, the switch detects the different MAC address and can block the unauthorized device or shut down the port.

4. Major Layer-2 Switch Security Features

4.1 Port Security

Port Security is a Layer-2 security feature that controls which MAC addresses are allowed to communicate through a particular switch port. An administrator can configure the maximum number of MAC addresses permitted on a port and define what happens when an unauthorized MAC address is detected.

Example: Suppose switch port GigabitEthernet 0/1 is connected to an employee’s desktop computer. The administrator configures Port Security to allow only one MAC address. If someone disconnects the desktop and connects another laptop, the switch detects the different MAC address and can restrict access or shut down the port.

4.2 802.1X Authentication

802.1X is a port-based network access authentication mechanism that verifies a user or device before allowing it to access the network. It commonly works with a RADIUS server to authenticate credentials.

It involves three main components:

  • Supplicant: Client device requesting network access.

  • Authenticator: Network switch controlling access.

  • Authentication Server: RADIUS server verifying credentials.

Example: In a company, employees connect their laptops to network switch ports. Before receiving network access, they must authenticate using their company credentials. If authentication succeeds, the switch allows access; otherwise, the device remains unauthorized.

4.3 MAC Address Filtering

MAC Address Filtering allows or denies network access based on the MAC address of a connected device. The switch administrator can configure specific MAC addresses that are permitted or denied.

Example: A school computer lab has 30 desktop computers. The administrator allows only the registered MAC addresses of those computers on specific switch ports. If an unknown device is connected, its MAC address can be denied.

4.4 DHCP Snooping

DHCP Snooping is a security feature that protects a network against Rogue DHCP Server attacks. It identifies trusted and untrusted switch ports and allows DHCP server messages only through trusted ports.

  • Trusted Port: Connected to an authorized DHCP server or trusted DHCP path.

  • Untrusted Port: Normally connected to client devices.

Example: An office has one authorized DHCP server. An attacker connects a personal router to a switch and activates its DHCP server. The attacker’s router starts assigning incorrect IP addresses and gateway information to employee computers. DHCP Snooping blocks unauthorized DHCP server responses from untrusted ports.

4.5 Dynamic ARP Inspection (DAI)

Dynamic ARP Inspection protects a network against ARP Spoofing and ARP Poisoning attacks. It checks ARP packets against trusted IP-to-MAC address bindings, commonly learned through DHCP Snooping.

Example: Suppose an employee’s computer uses IP address 192.168.1.10 and MAC address AA:AA:AA:AA:AA:AA. An attacker sends fake ARP messages claiming that the gateway IP address belongs to the attacker’s MAC address. DAI checks the ARP information and drops invalid packets, helping prevent traffic interception.

4.6 IP Source Guard

IP Source Guard is a security feature that prevents IP address spoofing on switch access ports. It checks the source IP and MAC address against configured IP source bindings and blocks unauthorized traffic.

Example: A computer is assigned IP address 192.168.1.20 through DHCP. An attacker manually configures another IP address to impersonate a different network device. IP Source Guard can block traffic that does not match the authorized binding.

4.7 Storm Control

Storm Control protects a switch and the network from excessive Broadcast, Multicast, and Unknown Unicast traffic. It monitors traffic levels on switch ports and limits traffic when it crosses a configured threshold.

Example: A faulty network device continuously sends thousands of broadcast packets. This excessive traffic consumes network bandwidth and affects other connected computers. Storm Control limits the broadcast traffic to reduce network congestion.

4.8 BPDU Guard

BPDU Guard protects the Spanning Tree Protocol (STP) topology by disabling an edge port when it receives an unexpected BPDU packet. It is generally enabled on PortFast access ports.

Example: In an office, a switch access port is connected to an employee’s desktop computer. Someone connects an unmanaged switch to that port, which starts sending STP BPDU packets. BPDU Guard detects the BPDU and places the port into an error-disabled state, helping prevent unauthorized switches from affecting the STP topology.

4.9 Root Guard

Root Guard prevents an unauthorized switch from becoming the STP Root Bridge. It protects the intended root bridge selection in the network topology.

Example: An enterprise network has a Core Switch configured as the Root Bridge. Someone connects another switch that advertises superior BPDU information. Root Guard prevents that port from accepting the superior BPDU and changing the intended root bridge.

4.10 VLAN Access Control

VLAN Access Control restricts which VLANs are allowed through a switch port. It helps prevent unauthorized VLAN access and reduces the risk of VLAN-related attacks.

Example: An office uses VLAN 10 for employees, VLAN 20 for servers, and VLAN 30 for guests. Guest devices should not have direct access to the employee VLAN. VLAN restrictions and appropriate Layer-3 ACLs help enforce this separation.

4.11 Private VLAN (PVLAN)

Private VLAN provides additional isolation between devices that belong to the same primary VLAN. It uses different port types, such as Promiscuous, Isolated, and Community ports, to control communication.

Example: A hotel connects 50 guest rooms to the same network infrastructure. Guests need internet access, but one guest should not directly communicate with another guest’s device. Private VLAN can isolate guest devices while allowing them to communicate with the authorized gateway.

1. Port Security: Restricts the number of MAC addresses allowed on a switch port and blocks unauthorized devices.
Example: Only one authorized PC is allowed on Port Fa0/1; connecting another laptop triggers a security violation.

2. DHCP Snooping: Prevents unauthorized DHCP servers from assigning fake IP addresses and gateway information to network devices.
Example: If an attacker connects a fake DHCP server to an office switch, DHCP Snooping blocks its DHCP Offer messages.

3. Dynamic ARP Inspection (DAI): Protects the network against ARP spoofing by validating ARP packets against trusted IP-MAC bindings.
Example: If an attacker sends fake ARP messages pretending to be the gateway, DAI blocks the invalid packets.

4. IP Source Guard (IPSG): Prevents IP spoofing by checking whether a device uses an authorized IP address on its switch port.
Example: If a PC is assigned 192.168.1.10, another unauthorized device cannot use that IP through a protected port.

5. 802.1X Authentication: Allows only authenticated users or devices to access the network through switch ports.
Example: An employee must authenticate using valid credentials before accessing the company’s network.

6. BPDU Guard: Protects the STP topology by disabling an edge port when it receives an unexpected BPDU.
Example: If someone connects an unauthorized switch to an office network port, BPDU Guard disables that port when it receives a BPDU.

7. Root Guard: Prevents an unauthorized switch from becoming the STP Root Bridge.
Example: If an access switch sends superior BPDU messages to challenge the core switch, Root Guard blocks the port from influencing the root selection.

8. Storm Control: Protects the network from excessive broadcast, multicast, and unknown unicast traffic.
Example: If a faulty device generates thousands of broadcast packets, Storm Control limits excessive traffic.

9. VLAN Security: Separates network devices into different logical networks to restrict unnecessary communication.
Example: Office PCs, CCTV cameras, and guest Wi-Fi are placed in separate VLANs.

10. SSH Management: Provides encrypted remote access to configure and manage network switches securely.
Example: An administrator uses SSH instead of Telnet to remotely manage a Cisco switch.

11. Unused Port Shutdown: Disables unused switch ports to prevent unauthorized users from connecting devices.
Example: An administrator shuts down all unused ports in an office switch.

12. Access Control List (ACL): Controls network traffic by permitting or denying communication based on configured rules.
Example: An ACL blocks the guest VLAN from accessing the company’s internal server network.

Common Layer-2 Network Attacks with Practical Examples

Layer-2 Network Attacks are security threats that target the Data Link Layer of the OSI Model. These attacks mainly exploit weaknesses in Ethernet switching, MAC address learning, ARP communication, VLAN configuration, and DHCP services. Attackers use these techniques to gain unauthorized network access, intercept data, disrupt communication, or affect network performance.

1. MAC Spoofing Attack

MAC Spoofing is an attack in which an attacker changes the MAC address of their network device to impersonate an authorized device. Since Layer-2 switches use MAC addresses to forward Ethernet frames, an attacker may attempt to gain access by copying the MAC address of a trusted computer.

Example: Suppose an office computer has MAC address AA:BB:CC:11:22:33 and is authorized to access the company network. An attacker connects a laptop and changes its MAC address to the same value. The attacker attempts to impersonate the authorized computer and bypass basic MAC-based access restrictions.

Prevention: Use Port Security, 802.1X Authentication, and proper network access control.

2. MAC Flooding Attack

MAC Flooding is an attack in which an attacker sends a large number of Ethernet frames with fake source MAC addresses to a switch. This can overwhelm the switch’s MAC address table. When the table becomes full, the switch may flood certain unknown unicast frames out of multiple ports within the VLAN, potentially exposing traffic to unauthorized devices.

Example: Suppose a managed switch has a limited MAC address table. An attacker connects a laptop to the switch and generates thousands of frames using different fake source MAC addresses. The switch’s MAC table may become full, affecting normal frame forwarding and potentially exposing traffic.

Prevention: Enable Port Security, limit the number of MAC addresses per access port, and monitor unusual MAC address activity.

3. ARP Spoofing / ARP Poisoning Attack

ARP Spoofing is an attack in which an attacker sends fake Address Resolution Protocol (ARP) messages to associate their MAC address with another device’s IP address, such as the default gateway. This can redirect network traffic through the attacker’s device and enable Man-in-the-Middle (MITM) attacks.

Example: Suppose a company network has a gateway IP address 192.168.1.1 and an employee computer with IP address 192.168.1.10. An attacker sends fake ARP messages claiming that the gateway IP belongs to the attacker’s MAC address. The employee’s computer may send traffic to the attacker’s device instead of the actual gateway.

Prevention: Enable Dynamic ARP Inspection (DAI), DHCP Snooping, and appropriate network security monitoring.

4. Rogue DHCP Server Attack

A Rogue DHCP Server attack occurs when an unauthorized DHCP server is connected to a network and starts providing incorrect IP configuration to client devices. It may assign a malicious default gateway or DNS server to redirect users’ network traffic.

Example: An office network uses an authorized DHCP server to assign IP addresses to employee computers. An attacker connects a personal Wi-Fi router to an unused switch port with its DHCP service enabled. Employee computers may receive IP addresses and gateway information from this unauthorized router instead of the official DHCP server.

Prevention: Enable DHCP Snooping and configure only authorized DHCP server-facing ports as trusted.

5. Broadcast Storm Attack

A Broadcast Storm occurs when an excessive number of broadcast frames circulate within a network, consuming bandwidth and switch processing resources. It may result from malicious traffic generation, faulty network devices, or switching loops.

Example: An attacker connects a device to the office network and continuously generates thousands of broadcast packets. Other computers receive excessive broadcast traffic, resulting in slow network performance, packet loss, and communication problems.

Prevention: Configure Storm Control, implement proper VLAN segmentation, and use STP to prevent switching loops.

6. VLAN Hopping Attack

VLAN Hopping is an attack in which an attacker attempts to access traffic belonging to another VLAN without proper authorization. Common techniques include Switch Spoofing and Double Tagging.

Example: An office network uses VLAN 10 for employees and VLAN 20 for servers. An attacker connected to an access port in VLAN 10 attempts to send specially crafted Ethernet frames to reach VLAN 20. If the switch configuration is vulnerable, the attacker may gain unauthorized access to another VLAN.

Prevention: Configure access ports manually, disable Dynamic Trunking Protocol (DTP) where appropriate, use unused VLANs for trunks, and restrict allowed VLANs on trunk ports.

7. STP Manipulation Attack

An STP Manipulation Attack occurs when an attacker connects an unauthorized switch and sends superior Bridge Protocol Data Units (BPDUs) to influence the Spanning Tree Protocol topology. The attacker may attempt to become the Root Bridge and change the network’s forwarding paths.

Example: An enterprise network has a Core Switch configured as the Root Bridge. An attacker connects another switch to an access port and sends BPDUs with a better bridge priority. If the network is not protected, the unauthorized switch may become the Root Bridge, changing traffic paths and potentially disrupting communication.

Prevention: Configure BPDU Guard on edge ports, Root Guard on appropriate designated ports, and maintain a secure STP design.

8. DHCP Starvation Attack

DHCP Starvation is an attack in which an attacker sends a large number of DHCP requests using different fake MAC addresses. The goal is to consume all available IP addresses in the DHCP address pool, preventing legitimate devices from obtaining IP addresses.

Example: A company DHCP server has an available pool of 100 IP addresses. An attacker generates thousands of DHCP requests using different spoofed MAC addresses. The DHCP server may allocate most or all available addresses, leaving genuine employee computers unable to obtain an IP address.

Prevention: Configure DHCP Snooping rate limiting, Port Security, and appropriate DHCP server protections.

9. Man-in-the-Middle (MITM) Attack

A Man-in-the-Middle attack occurs when an attacker secretly positions themselves between two communicating devices to intercept or potentially modify network traffic. At Layer 2, this may be achieved through techniques such as ARP Spoofing.

Example: An employee accesses an internal company application through the LAN. An attacker performs ARP Poisoning to redirect traffic through their laptop. The attacker may observe or manipulate unencrypted communication between the employee and the gateway.

Prevention: Use Dynamic ARP Inspection, encrypted protocols such as HTTPS and SSH, proper authentication, and network monitoring.

Switch Security Best Practices

1. Enable Port Security: Port Security should be enabled on access ports to prevent unauthorized devices from connecting to the network. Administrators can configure a maximum number of MAC addresses and define actions when an unknown device is detected. This helps protect office and enterprise networks from unauthorized access.

Example: In an office, each employee’s PC is connected to a dedicated switch port. The administrator allows only one authorized MAC address per port. If someone disconnects the employee’s PC and connects another laptop, the switch detects the violation and blocks access according to the configured policy.

2. Enable DHCP Snooping: DHCP Snooping should be configured to prevent unauthorized DHCP servers from assigning incorrect IP addresses, gateway addresses, and DNS information. The administrator configures trusted ports toward the legitimate DHCP server infrastructure and keeps user-facing ports untrusted. This protects the network from rogue DHCP server attacks.

Example: In a company network, an attacker connects a laptop running a fake DHCP server. DHCP Snooping blocks DHCP server responses arriving through the untrusted access port, allowing legitimate DHCP services to operate safely.

3. Enable Dynamic ARP Inspection (DAI): DAI should be enabled to protect the network against ARP spoofing and ARP poisoning attacks. It validates ARP packets using trusted IP-to-MAC address bindings, generally learned through DHCP Snooping. This helps prevent attackers from impersonating gateways or other network devices.

Example: An attacker sends fake ARP messages claiming that their laptop is the default gateway. DAI checks the IP and MAC address information and drops invalid ARP packets before they can redirect network traffic.

4. Disable Unused Switch Ports: All unused switch ports should be administratively disabled to prevent unauthorized users from connecting laptops, switches, or other devices. Administrators should also assign unused ports to an isolated unused VLAN as an additional security measure.

Example: In an office, a 48-port switch has only 30 active connections. The administrator disables the remaining 18 unused ports so that unauthorized users cannot connect devices through them.

5. Use SSH Instead of Telnet: SSH should be used for remote switch management because it encrypts communication between the administrator’s computer and the switch. Telnet sends usernames, passwords, and commands without encryption, making them vulnerable to interception.

Example: A network administrator remotely accesses a Cisco switch using SSH from the IT department. Even if someone captures network traffic, the management session remains encrypted.

6. Enable 802.1X Authentication: 802.1X should be implemented to authenticate users or devices before granting network access. It uses a switch as the authenticator and typically a RADIUS server to verify credentials. This provides stronger access control than relying only on MAC address filtering.

Example: In a corporate office, employees must authenticate using their company credentials before their laptops can access internal network resources. Unauthorized devices are denied normal network access.

7. Configure BPDU Guard and Root Guard: BPDU Guard should be enabled on appropriate end-device edge ports to prevent unauthorized switches from participating in STP. Root Guard should be configured on suitable ports to prevent unexpected superior BPDUs from changing the intended Root Bridge.

Example: In a campus network, the core switch is configured as the STP Root Bridge. If someone connects an unauthorized switch to an edge port, BPDU Guard can disable that port when it receives a BPDU, helping protect the network topology.

8. Implement VLAN Segmentation: Different departments and devices should be separated into different VLANs to reduce unnecessary communication and improve network security. Access between VLANs should be controlled using ACLs or firewall policies.

Example: In a company, the administrator creates separate VLANs for HR, Finance, CCTV, Servers, and Guest Wi-Fi. Guest users are prevented from accessing sensitive HR and Finance servers through appropriate security rules.

9. Configure Access Control Lists (ACLs): ACLs should be configured to permit or deny network traffic based on source IP, destination IP, protocol, and port information. They help restrict unauthorized communication between network segments and protect sensitive resources.

Example: In a company, an ACL allows the Finance VLAN to access the accounting server but blocks the Guest VLAN from accessing the internal server network.

10. Regularly Update Switch Firmware: Switch firmware should be updated regularly to fix security vulnerabilities, improve performance, and protect against known attacks. Administrators should check vendor security advisories and test firmware updates before deploying them in production networks.

Example: If a switch manufacturer releases a security update to fix a vulnerability in its management interface, the network administrator installs the tested firmware update to reduce the risk of exploitation.

11. Monitor Switch Logs and Network Traffic: Switch logs, security events, and network traffic should be monitored regularly to identify suspicious activities such as MAC address changes, port-security violations, excessive broadcasts, and unauthorized access attempts. Centralized monitoring tools such as Syslog and SNMPv3 can help administrators detect problems.

Example: If a switch port repeatedly detects unauthorized MAC addresses, the administrator receives an alert and investigates whether someone is attempting to connect an unauthorized device.

12. Secure Switch Management Access: Switch management access should be restricted to authorized administrators using a dedicated management VLAN, strong passwords, ACLs, and secure management protocols. Default credentials should be changed, and unnecessary management services should be disabled.

Example: In a data center, only the IT administrator’s management subnet is permitted to access the switch management IP address. Users from ordinary office VLANs cannot directly access the switch configuration interface.

What is Port Security

Port Security is a network switch security feature that allows only specific or limited MAC addresses to connect to a switch port and blocks or disables the port when an unauthorized device tries to access the network, helping to protect the LAN from unknown devices and security threats.

Port Security – Example 

Example 1 (Office Network)

In a company office, Port 5 of a switch is assigned to a desktop computer with MAC address 00:1A:2B:3C:4D:5E. Port Security is enabled so only this device can use the port. If another laptop is connected to Port 5, the switch detects a different MAC address and blocks the connection or shuts down the port.


Example 2 (School Lab)

In a computer lab, each switch port is configured with Port Security to allow only one PC per port. If a student tries to connect a personal laptop or switch to the same port, the network blocks it, preventing unauthorized access and maintaining control over the lab network.


Example 3 (Server Room)

A server is connected to a switch port with Port Security enabled. Only the server’s MAC address is allowed. If someone tries to connect another device to that port, the switch immediately disables the port to protect important business data and services.

1. Definition

Port Security is a security feature available on managed network switches that controls which devices are allowed to connect to a specific switch port. It works mainly by checking the MAC address of connected devices. The network administrator can configure the switch port to accept only approved MAC addresses or limit how many devices can connect to that port. This prevents unknown or unauthorized devices from joining the network.

2. How Port Security Works

When a device connects to a secured switch port, the switch reads the device’s MAC address and compares it with the allowed MAC address list configured on that port. If the MAC address matches, the device is allowed to communicate on the network. If the MAC address is unknown or exceeds the allowed device limit, the switch treats it as a security violation and takes action based on configuration.

3. Violation Actions

If an unauthorized device connects, the switch can respond in different ways. In Protect mode, the switch silently drops traffic from the unauthorized device. In Restrict mode, the switch drops traffic and also records logs or sends alerts to the administrator. In Shutdown mode, the switch completely disables the port until the administrator manually enables it again. Shutdown mode is commonly used for stronger security.

4. Why Port Security Is Needed

Port Security is important because it protects the network from unauthorized access. Without it, any person could connect a laptop, switch, or unknown device to an office network port and gain access to internal resources. Port Security also helps prevent MAC flooding attacks, where attackers try to overload the switch MAC table to intercept traffic. It improves control over who and what can connect to the network.

5. Real Example

Suppose a company office PC with MAC address 00:1A:2B:3C:4D:5E is connected to Switch Port 5. The administrator configures Port Security to allow only that MAC address on that port. Later, if someone disconnects that PC and connects an unauthorized laptop, the switch detects a different MAC address and blocks communication or shuts down the port. This prevents unauthorized network access.

6. Where It Is Used

Port Security is mostly used on access ports, where end devices such as computers, printers, IP phones, and office workstations connect. It is commonly used in company offices, schools, banks, hospitals, and enterprise networks where network access must be controlled for security reasons.

7. Benefits

Port Security improves LAN security, blocks unauthorized devices, limits the number of connected devices per port, protects against certain network attacks, and gives network administrators better control over switch port access. It is a simple but effective security feature for wired networks.

Port Security Example

1. Company Office Setup

In a company office network, each employee desk is connected to a managed switch port. Suppose Port 10 of the switch is assigned to one employee’s desktop computer. The network administrator enables Port Security on that port so that only the authorized office desktop can use that network connection. This helps ensure that only approved company devices can access the internal network.

2. Allowed Device Configuration

The administrator configures Port Security with the desktop computer’s MAC address, for example 00:1A:2B:3C:4D:5E, and sets the maximum allowed device count to one. This means only that specific computer is permitted to connect on Port 10. If the correct device is connected, the switch recognizes the MAC address and allows normal communication.

3. Normal Network Operation

When the authorized office desktop is connected to Port 10, it can access company resources normally. The employee can connect to servers, use printers, browse the internet, and access internal applications because the switch verifies that the MAC address matches the allowed configuration. The port remains active and traffic flows normally.

4. Unauthorized Device Connection

Later, if someone disconnects the office desktop and connects a personal laptop or unknown device to the same port, the switch reads the new MAC address. Since that MAC address is not in the allowed list, the switch detects it as a Port Security violation. This immediately triggers the security action configured on that port.

5. Switch Response

Depending on Port Security settings, the switch may block traffic silently, send an alert, or completely shut down the port. In many office networks, Shutdown mode is used for stronger protection. In this case, Port 10 becomes disabled, and the unauthorized device receives no network access until the administrator manually enables the port again.

6. Real Business Benefit

This protects the company network from unauthorized employee devices, visitor laptops, rogue switches, and accidental connections. It ensures that only approved company systems can use network ports, improving wired network security and helping administrators maintain better access control across the office LAN.

Port Security Modes

1. Protect Mode

In Protect mode, when an unauthorized device connects to the switch port, the switch simply drops traffic from that device. The unauthorized device cannot communicate on the network, but the port remains active for authorized devices. No alert or log message is usually generated. This mode provides basic protection without shutting down the port.

Example:
Allowed MAC = 00:1A:2B:3C:4D:5E
Unknown laptop connects → traffic blocked → port stays ON.


2. Restrict Mode

In Restrict mode, the switch blocks traffic from the unauthorized device just like Protect mode, but it also records the violation in logs and may send an alert (such as SNMP trap/syslog) to the network administrator. The port remains active for authorized devices, making it useful when administrators want security monitoring without port shutdown.

Example:
Unknown device connects → traffic blocked + alert sent to admin → port stays ON.


3. Shutdown Mode

In Shutdown mode, when an unauthorized device connects, the switch treats it as a serious security violation and disables the port completely. The port enters an error-disabled (err-disable) state and stops all communication until an administrator manually enables it again or automatic recovery is configured. This is the most secure mode and is commonly used in enterprise networks.

Example:
Unknown laptop connects → violation detected → Port 10 shuts down → no network access.

What is Port Security Sticky and Manual MAC

1. Manual Secure MAC Address Entry

In Manual Port Security mode, the network administrator manually configures the MAC address that is allowed on a specific switch port. The switch stores this MAC address as a secure address, and only that approved device can use the port. If another device with a different MAC address connects to that port, the switch detects it as a Port Security violation and blocks traffic, sends an alert, or shuts down the port depending on the configured security mode. Manual configuration provides strong security because access is tightly controlled by the administrator.

Example: A company desktop computer with MAC address 00:1A:2B:3C:4D:5E is manually configured on Port 10. When that desktop connects, network access is allowed. If someone connects a different laptop with another MAC address, the switch blocks access or disables the port.

2. Sticky Secure MAC Address Automatically

In Sticky Port Security mode, the switch automatically learns the MAC address of the first device connected to the port and saves it as a secure MAC address. After learning that address, the switch allows only that device to use the port. If another device with a different MAC address is connected later, it is treated as an unauthorized device and Port Security action is triggered. Sticky mode reduces manual configuration work because administrators do not need to enter MAC addresses one by one, making it useful in large networks.

Example: A new office PC connects to Port 15 with MAC address AA:BB:CC:DD:EE:FF. The switch automatically learns and stores that MAC address. Later, if another laptop is connected to Port 15, the switch detects the MAC mismatch and blocks the connection.

3. Difference Between Manual and Sticky

The main difference is how the secure MAC address is learned. In Manual mode, the administrator manually enters the allowed MAC address in the switch configuration. In Sticky mode, the switch automatically learns and stores the MAC address of the connected device. Manual mode gives more control and stronger planned security, while Sticky mode makes deployment easier and faster in environments with many devices.

4. Where They Are Used

Manual Port Security is commonly used for fixed devices such as office desktops, servers, printers, and important systems where the administrator wants strict access control. Sticky Port Security is often used in larger office networks where many access ports must be secured quickly, because the switch can automatically learn device MAC addresses without manual entry. Both methods improve switch port security and help prevent unauthorized devices from joining the network.

Why Need Port Security in Company Network

In a company network, port security is needed to protect the network from unauthorized devices and internal attacks. When port security is enabled on a switch (for example on devices running Cisco IOS), the administrator can limit which MAC addresses are allowed to connect to each switch port. This ensures that only approved computers or devices can access the company network. It also helps control how many devices can connect to a port, which improves overall network security and management.

Without port security, several problems can occur in a company network. Any person could plug a laptop or unauthorized device into an open switch port and gain access to internal resources such as files, printers, or servers. Attackers may also perform MAC flooding attacks, which can overload the switch’s MAC address table and allow them to capture network traffic. Additionally, employees might connect personal devices that introduce malware or cause network misuse. Because of these risks, companies use port security to prevent unauthorized access, protect sensitive data, and maintain stable network performance.

Frequently Asked Questions

Q1. Why is port security important?

Due to the open nature of the switch ports in Ethernet LANs, several assaults, such as layer-2 DoS attacks and address spoofing, are possible. Port security is an effective means of securing a network by preventing unauthorized devices from forwarding packets. You may limit the number of MAC addresses, configure static MAC addresses, and penalize unauthorized users with the help of port security.

Q2. What layer is port security?

Port security is a Layer 2 security feature that may be implemented on each port of a switch. Its purpose is to filter incoming frames based on the media access control (MAC) addresses of the devices that are connected to the switch.

Q3. What are the 3 types of port security?

There are mainly 3 types of port security violations. These are:

  • Shutdown
  • Protect
  • Restrict

When the switch’s port security violation feature is on, each port may be set to use one of three violation modes, each defining the actions to be taken in the event of a security violation.

Q4. What are the methods of port security?

Mainly there are two methods of port security. These are:

  • Static
  • Dynamic

One can use the above two methods individually or can be used concurrently.

Port Security Configuration in Cisco Switch

 

There is a security saying – “The network is only as strong as its weakest link.” On a campus LAN, the weakest part is often not the core or the internet edge but the access layer. Anyone can plug a cable into the wall jack leading to the access switch. And the switch, by default, will forward traffic for whatever device shows up—PC, printer, or a rogue laptop.

Why do we need port security?

Access switches live at the edge, where humans and devices connect. That edge is the most dynamic layer of the network. People move desks. Contractors and suppliers visit. IP phones sit between PCs and switches. Printers get swapped and so on. It is one of the network’s weakest layers. Let’s consider the following example.

Imagine an open office space with desks everywhere. What stops someone with access to the office from unplugging a device at an empty desk and plugging their rogue device into the wall jack, as shown in the diagram?

 

				
					Switch# configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface Ethernet0/1
Switch(config-if)# switchport port-security
Command rejected: Ethernet0/0 is a dynamic port.
				
			
				
					Switch(config)# interface Ethernet0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 20
Switch(config-if)# switchport port-security
!
				
			
				
					Switch(config-if)# switchport port-security ?
  aging        Port-security aging commands
  mac-address  Secure mac address
  maximum      Max secure addresses
  violation    Security violation mode
  <cr>         <cr>
				
			
				
					interface Ethernet0/1
 switchport mode access
 switchport access vlan 20
 switchport port-security
 switchport port-security maximum 2
				
			
				
					interface Ethernet0/1
 switchport access vlan 10
 switchport port-security
 switchport port-security mac-address 0011.2233.4455

				
			
				
					interface Ethernet0/1
 switchport access vlan 10
 switchport port-security
 switchport port-security mac-address sticky
				
			
				
					Switch# show mac address-table interface eth0/1
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
  20    aabb.cc00.7000    STATIC      Et0/1
Total Mac Addresses for this criterion: 1
				
			
				
					Switch# show run int Et0/0
Building configuration...

Current configuration : 235 bytes
!
interface Ethernet0/1
 switchport access vlan 20
 switchport mode access
 switchport port-security
 switchport port-security mac-address sticky
 switchport port-security mac-address sticky aabb.cc00.7000
end
				
			
				
					Switch# copy running-config startup-config
Destination filename [startup-config]?
Building configuration...
[OK]
				
			
				
					Switch(config-if)# switchport port-security violation ?
  protect   Security violation protect mode
  restrict  Security violation restrict mode
  shutdown  Security violation shutdown mode
				
			
				
					Switch# configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface Ethernet0/1
Switch(config-if)# shutdown
Switch(config-if)# no shutdown
				
			
				
					Switch# configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# errdisable recovery cause psecure-violation
Switch(config)# errdisable recovery interval 300
				
			
				
					Switch(config)# errdisable recovery cause ?                
  all                   Enable timer to recover from all error causes
  arp-inspection        Enable timer to recover from arp inspection error
                        disable state
  bpduguard             Enable timer to recover from BPDU Guard error
  channel-misconfig     Enable timer to recover from channel misconfig error
                        (STP)
  dhcp-rate-limit       Enable timer to recover from dhcp-rate-limit error
  dtp-flap              Enable timer to recover from dtp-flap error
  gbic-invalid          Enable timer to recover from invalid GBIC error
  inline-power          Enable timer to recover from inline-power error
  l2ptguard             Enable timer to recover from l2protocol-tunnel error
  link-flap             Enable timer to recover from link-flap error
				
			

Port Security Configuration With 5 Devices

				
					Sticky Port Security Configuration (Allow 5 Devices)
....................................................
1. Enter Interface Mode
Switch# configure terminal
Switch(config)# interface fastEthernet 0/1


2. Set Port as Access Port and Enable Port Security
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security

3. Set Maximum 5 Devices
Switch(config-if)# switchport port-security maximum 5

4. Enable Sticky MAC Learning
Switch(config-if)# switchport port-security mac-address sticky

5. Set Violation Mode (Example: Shutdown)
Switch(config-if)# switchport port-security violation shutdown

6. Save Configuration
Switch# write memory


Manual Port Security Configuration (5 Devices)
..............................................

1. Enter Interface Mode
Switch# configure terminal
Switch(config)# interface fastEthernet 0/1


2. Set Port as Access Port and Enable Port Security
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security

3. Set Maximum 5 Devices
Switch(config-if)# switchport port-security maximum 5

4. Manually Add Allowed MAC Addresses (5 Devices)
Switch(config-if)# switchport port-security mac-address 00:11:22:33:44:01
Switch(config-if)# switchport port-security mac-address 00:11:22:33:44:02
Switch(config-if)# switchport port-security mac-address 00:11:22:33:44:03
Switch(config-if)# switchport port-security mac-address 00:11:22:33:44:04
Switch(config-if)# switchport port-security mac-address 00:11:22:33:44:05

5. Set Violation Mode (Example: Shutdown)
Switch(config-if)# switchport port-security violation shutdown

6. Save Configuration
Switch# write memory

Port Security Show Commands
...........................
1. Check Port Security Status (All Interfaces)
show port-security

2. Check Specific Interface Status
show port-security interface fastEthernet 0/1

3. Show Secure MAC Addresses
show port-security address

4. Show Running Configuration
show running-config

5. Show MAC Address Table (Helpful)
show mac address-table

6. Check Disabled Port Status
show interface status

7. Manually Recover (Reset Port)
configure terminal
interface fastEthernet 0/1
shutdown
no shutdown

				
			

What is Port Security? 

Port Security is a switch feature that controls which devices can connect to a switch port using their MAC address.It allows only authorized devices and blocks unknown devices to improve network security.

How does Port Security Works

As we know about the switch, it’s a layer 2 device that stores the MAC Address of connected clients, and to verify this – we have a lab ready, have a look at the topology given below.

We got one switch and five clients connected to this switch, and all the clients’ MAC Addresses are also mentioned on the topology.

Let’s see the output of the MAC table inside the switch using the command –

				
					Switch#show mac address-table


				
			

If you want to see how many total Mac Addresses your switch can store inside the CAM Table so, there is a command to verify that as well i.e.

				
					Switch#show mac address-table count



				
			

By default, we know all interfaces on Cisco switches are turned on. That means that an attacker can connect to your network through another available port and potentially threaten your network. If you know which devices will be connected to which ports, you can use the Cisco security feature called port security.

By using port security, a network admin can reserve a specific MAC address with the interface, which can prevent an attacker from connecting his device. This is how you can restrict access to an interface so only authorized devices can use it. If an unauthorized device is connected, you can decide what action the switch will take, for example, discard the traffic or shut down the port and put the port in an err-disable state.

It adds an additional layer of security to the switching network.

Let’s take a scenario to understand the concept of port security in more detail –

Let’s say if an attacker is sitting inside your LAN, and he got access to your switch with any port that is not in use. There are many operating systems in the market, like Kali Linux; using this kind of OS, the attacker can send many fake MAC entries to the switch, and when the switch will receive the fake frames with fake MAC Addresses. The switch will store the MAC entry inside the CAM table.

Suppose your switch has total address space available in the CAM Table of 100 MAC Entries. Using the fake frames, the attacker fills the MAC Table, and in this kind of scenario, when the MAC table is completely filled, the switch starts acting like a HUB. Whenever a frame is received on the switch, the switch will broadcast in the network, allowing the attacker to capture the traffic, and the attacker can see what’s going on inside the network.

So, this is what we call a MAC Table overflow attack and preventing these types of attacks in Port Security.

Port Security allows you to limit the MAC-Address on the interface. So basically, by using it, you can assign a number of MAC addresses, and you can fix on port with static MAC entry.

Role of Port Security in Networking

Port security can provide several benefits for network security and performance, such as:

  • Preventing the ability of unauthorized devices to access protected network information and resources.
  • Keeping malicious software and viruses out of the network by blocking access from unapproved devices.
  • Preventing unauthorized devices from consuming bandwidth or causing congestion on the network.
  • Preventing spoofing and impersonation by unauthorized network devices.
  • The elimination of network loops and broadcast storms caused by malicious devices.

It assists network administration and troubleshooting by showing which devices are connected to which ports and detecting any topological changes or anomalies.

Key Features of Port Security

Here are some features of Port Security in Networking:

  • MAC Address Control: It can be used to control various devices using MAC Addresses.
  • Device Limitation: It lets you set a limit on the number of devices that can connect to a port.
  • Violation Action: Port security can itself respond to security violations in three ways: Protect, Restrict, and Shutdown.

Port Security Violation Types

Port security violation types are the actions that trigger a response when a device tries to connect to a switch port that is configured with port security. It has three violation parameters.

  1. Shutdown
  2. Protect
  3. Restrict

Let’s understand each port security violation in detail.

Shutdown

When any unauthorized device tries to connect to the port which is configured with port security shutdown violation, the port immediately goes into an err-disable state. This shutdown violation is also the default violation mode.

To configure shutdown – Let’s go on the switch CLI and run the following commands.

				
					Switch>enable
Switch#configure terminal
Switch(config)#interface fa0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport port-security
Switch(config-if)#switchport port-security mac-address 0030.A3C4.C9C7


				
			

(By this command we have statically assigned the MAC Address to interface fa0/1 with shutdown violation)

				
					Switch(config-if)#switchport port-security violation shutdown


				
			

Now to verify the output of port security on interface fa0/1,

Run the following command –

				
					Switch#show port-security interface fa0/1



				
			

Now, on this interface, if the attacker tries to access the port will automatically go into the err-disable state which means shutdown and to turn the port you have to manually select the interface shutdown and then run the command no shut down.

FastEthernet0/1 is down, line protocol is down (err-disabled)

Protect

The port is allowed to stay up. As this port reaches its MAC add limit, it stops learning MAC Address. Although packets from violations dropped, no record of violation is kept.

When it comes to the violation parameter, which is protected, so here, when the attacker tries to connect with any interface configured with protect violation, the port will stay up. Still, the attacker won’t be able to communicate inside the LAN. The switch will stop learning the MAC and will drop the frame.

To configure port-security protect use the following commands –

				
					Switch(config-if)#switchport port-security violation protect


				
			

By this keyword sticky we have done the automatic assignment of the MAC Address to interface fa0/2 which means that after assigning this command the user who’ll first send the frame to interface fa0/2. The MAC of the user who’ll first send the frame will stick to interface fa0/2

				
					Switch>enable
Switch#configure terminal
Switch(config)#interface fa0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport port-security
Switch(config-if)#switchport port-security mac-address sticky


				
			

Verify the MAC entries as well –