Instiq
Chapter 5 · Security Fundamentals·v1.0.0·Updated 7/18/2026·~16 min

What's changed: Initial version

5.4Layer 2 security

Key points

Covers port security that limits which MACs can connect to a switch port (violation modes protect/restrict/shutdown, sticky MAC), DHCP snooping that eliminates rogue DHCP servers (trusted/untrusted ports and the binding table), and Dynamic ARP Inspection (DAI) that uses those bindings to prevent ARP spoofing—so you can judge which L2 controls to combine from an attack scenario.

Even if you harden L3 and above with firewalls and ACLs, an attacker who plugs a device into an internal-LAN switch port can carry out Layer 2 attacks such as MAC flooding, a rogue DHCP server, and ARP spoofing. Because L2 attacks occur "within the same segment," L3 controls cannot stop them. This section covers the three representative L2 security features you should enable on access switches, focusing on "which attack each one stops and by what mechanism."

5.4.1Port security

  • Port security limits the number and identity of MAC addresses allowed on an access port. When the allowed count is exceeded or a disallowed MAC appears, it is handled as a "violation." The baseline config is switchport mode accessswitchport port-securityswitchport port-security maximum N (the maximum). The default maximum is 1.
  • Allowed MACs can be registered manually (switchport port-security mac-address ADDRESS) or via sticky MAC (switchport port-security mac-address sticky), which dynamically learns the first MAC into the allow list and saves it to the running-config. This pins "the legitimate device currently connected" without manual entry.
  • The violation action is chosen from three via switchport port-security violation. protect silently drops violating frames (no log or counter increment). restrict drops violating frames and sends an SNMP trap/Syslog and increments the counter. shutdown (the default) puts the port into an err-disabled state, shutting it down, and notifies; recovery requires shutdown then no shutdown, or errdisable recovery.

5.4.2DHCP snooping and DAI

  • DHCP snooping has the switch monitor DHCP messages to prevent a rogue DHCP server from handing out a fake default gateway, etc. It classifies ports as trusted/untrusted, marking only uplinks toward the legitimate DHCP server as trusted. DHCP server replies (OFFER/ACK) arriving on an untrusted port are dropped. Enable with ip dhcp snooping plus ip dhcp snooping vlan X, and ip dhcp snooping trust on trusted ports.
  • DHCP snooping records legitimately issued leases in a binding table (a mapping of MAC, IP, VLAN, port, and lease info). This table becomes the foundation for DAI, described next.
  • Dynamic ARP Inspection (DAI) prevents man-in-the-middle attacks via ARP spoofing (ARP poisoning). It inspects ARP packets received on untrusted ports against the DHCP snooping binding table and drops forged ARP whose IP-MAC mapping is inconsistent. Thus DAI depends on DHCP snooping, and in dynamic environments snooping must be enabled first (static environments use ARP ACLs). Enable with ip arp inspection vlan X.
Exam point

Most-tested: port-security violation modes = protect (silently drop) / restrict (drop + notify + counter) / shutdown (default, err-disabled); sticky MAC = learned MAC saved to config; DHCP snooping = eliminates rogue DHCP via trusted/untrusted; and DAI depends on the DHCP snooping binding table to prevent ARP spoofing. Be sure to grasp the dependency that DAI does not work alone and requires DHCP snooping first.

Suppose you operate the internal access switches and are investigating an incident on one floor: "some users suddenly lost internet access, and their traffic is suspected of being eavesdropped." You find that someone connected a small router to an empty conference-room port and (A) that router acts as a rogue DHCP server distributing a fake default gateway, and (B) it also forges ARP replies to lure victims' traffic through itself (the attacker) in a man-in-the-middle attack. Mitigating both attacks at once takes more than a single feature. For (A), the rogue DHCP, enable DHCP snooping and trust only the uplink toward the legitimate DHCP server while leaving user-side ports untrusted, so forged DHCP replies (OFFER/ACK) arriving on untrusted ports are dropped. For (B), the ARP spoofing, enable DAI—but the key is the dependency that DAI validates IP-MAC legitimacy by referencing the binding table that DHCP snooping builds. In other words, DAI will not work correctly unless DHCP snooping is enabled first. Additionally, to deter "plugging an unauthorized device into an empty port" in the first place, limit the allowed MAC count with port security and handle violations with restrict (drop + notify) or shutdown, detecting and blocking the unauthorized connection itself. The crux of the judgment is to combine, in layers rather than singly, "rogue DHCP = DHCP snooping," "ARP spoofing = DAI (but dependent on snooping)," and "unauthorized physical connection = port security."

FeatureAttack preventedKey mechanism
Port securityMAC flooding, unauthorized device connectionLimits allowed MAC count/identity per port; violation = protect/restrict/shutdown
DHCP snoopingRogue DHCP serverAllows DHCP replies only on trusted ports, drops untrusted OFFER/ACK, records bindings
DAIARP spoofing (MITM)Inspects untrusted-port ARP against the binding table, drops forged ARP (depends on snooping)
Warning

Trap: "Enabling DAI makes DHCP snooping unnecessary" is wrong—in dynamic environments DAI references the binding table that DHCP snooping builds, so it will not function correctly unless snooping is enabled first. Also wrong: "port security's protect and restrict are the same"—protect silently drops with no notification, while restrict drops and also notifies and increments the counter. And "set DHCP snooping trusted ports on the user-device side" is wrong; trusted ports are set on the uplink toward the legitimate DHCP server.

Port security violation modes, DHCP snooping and DAI.
Protecting the access layer from rogue devices

5.4.3Section summary

  • Port security limits allowed MACs; on violation choose protect (silent drop), restrict (drop + notify), or shutdown (default, err-disabled). Sticky MAC saves learned MACs to config
  • DHCP snooping eliminates rogue DHCP via trusted/untrusted ports and records legitimate leases in a binding table
  • DAI prevents ARP spoofing but depends on DHCP snooping because it references the binding table (snooping must be enabled first)

Sign in to track progress — Log in.

Quick check

(just a quick review)

Q1. On one floor, a device an attacker connected to an empty port was simultaneously acting as a "rogue DHCP server handing out a fake default gateway" and performing "a MITM attack by forging ARP replies." Which combination of measures best mitigates these?

Q2. You configure port security on an access port and want, on violation, to "drop violating frames while notifying the administrator via SNMP trap/Syslog and incrementing the violation counter, but keep the port itself operational." Which violation mode is most appropriate?

Q3. Which is the most appropriate policy for setting trusted vs untrusted ports in DHCP snooping?

Check your understandingPractice questions for Chapter 5: Security Fundamentals

Keep track of your progress

The full study guide is free to read. Sign up free to practice with the question bank, track what you have read, review your mistakes, and highlight passages.