Layer 2 Security Configuration
Routers and firewalls patrol the network edge, but most attackers are already inside the building — plugged into a wall port. Layer 2 security is what protects the switch itself: port security against rogue devices, DHCP snooping against fake DHCP servers, DAI against ARP poisoning, BPDU guard against rogue switches, and storm control against broadcast floods. Each is a small feature with one precise job, and each maps to exam questions.
- Configure port security: switchport port-security, maximum, mac-address, and sticky.
- Compare the three violation modes protect, restrict, shutdown.
- Recover err-disabled ports and configure errdisable recovery.
- Explain and configure DHCP snooping with trusted and untrusted ports.
- Describe Dynamic ARP Inspection, 802.1X, BPDU guard, and root guard.
- Control broadcast storms with storm control.
Why the access layer needs security
A switch forwards frames based on MAC addresses and believes whatever it hears. Attackers exploit that trust: a rogue device can feed the switch bogus MACs (MAC flooding), impersonate another host (ARP poisoning), or offer its own DHCP service and redirect clients. Each Layer 2 attack is cheap to run and totally invisible to an edge router, so the defence must live on the switch itself.
Layer 2 security tools divide into two families: port-based controls (port security, BPDU guard, spanning-tree protection) and protocol-based validation (DHCP snooping, DAI, 802.1X). A complete access-layer design uses several at once because they defend different threats. The table below is the whole map:
| Feature | Attack it mitigates | How |
|---|---|---|
| Port security | Rogue device / MAC flooding | Limits MACs per port |
| DHCP snooping | Rogue DHCP server | Trusts only designated ports |
| DAI | ARP poisoning / man-in-the-middle | Validates ARP against the DHCP binding |
| 802.1X | Unauthorised endpoint | Authenticates devices at the port |
| Root guard | Rogue root bridge takeover | Stops STP root election changes |
| BPDU guard | Layer 2 loop / rogue switch | Shuts ports that send BPDUs |
| Storm control | Broadcast/multicast flood | Caps traffic rate per port |
Port security configuration
Port security applies to access ports only, so the port must first be switched to access mode. The feature tracks how many MAC addresses the port may learn and what happens when the limit is exceeded:
S1(config)# interface fastethernet0/1 S1(config-if)# switchport mode access S1(config-if)# switchport port-security S1(config-if)# switchport port-security maximum 1 S1(config-if)# switchport port-security mac-address sticky S1(config-if)# switchport port-security violation restrict S1(config-if)# end S1# show port-security interface fastethernet0/1
Round trip through the syntax:
switchport port-security— turns the feature on. Unless stated otherwise, the default maximum is 1 address and the default violation mode is shutdown.switchport port-security maximum <n>— how many MAC addresses this port may hold.switchport port-security mac-address <mac>— manually hard-code a MAC (used for fixed devices).switchport port-security mac-address sticky— dynamically learns the current device’s MAC and writes it into the running config as a sticky entry. Save the config or the entry vanishes at reboot.switchport port-security violation <mode>— the reaction when a frame with an unknown MAC arrives.
Violation modes: protect, restrict, shutdown
When an unknown MAC arrives on a secured port, the mode decides the response. Remember these in order of severity and exactly what each one does:
| Mode | Behaviour on violation | Logs / counter |
|---|---|---|
protect | Silently drops unknown frames. Existing secure addresses keep working. | No syslog, no SNMP trap |
restrict | Drops unknown frames like protect, but also notifies. | Syslog + SNMP trap + SecurityViolation counter |
shutdown | The whole port enters the err-disabled state; all traffic stops. | Log generated; port dead until recovered |
protect;
mention logging or a counter → restrict; mention
err-disable → shutdown (which is also the default).
Severity order: protect → restrict → shutdown.
err-disable and recovery
When a port is err-disabled, the interface state reads err-disabled and the switch has stopped forwarding on it completely. Recovery is manual by default:
! Manual recovery: bounce the port S1(config)# interface fastethernet0/1 S1(config-if)# shutdown S1(config-if)# no shutdown S1(config-if)# exit ! Automatic recovery after 300 seconds S1(config)# errdisable recovery cause psecure-violation S1(config)# errdisable recovery interval 300
Why the shutdown/recovery dance? IOS leaves the port dead until an administrator fixes the real
problem (a new attacker or a misconfigured NIC), so a malicious device cannot simply re-trigger traffic
forever. Use show errdisable detect and show interface status to confirm the
cause; the reason string (for example psecure-violation) tells you which feature disabled
the port.
shutdown violation mode. A port in
protect or restrict mode keeps running and simply drops the offending MACs.
DHCP snooping
DHCP snooping protects against a rogue DHCP server handing out wrong addresses. The switch builds a DHCP snooping binding table (MAC → IP → port → VLAN) as it watches legitimate DORA exchanges, then filters DHCP offer/ack frames: they are only accepted from trusted ports (the ports facing a real DHCP server or between switches). Client ports are untrusted and may only send DHCP discover/request messages; a rogue DHCP offer from a client port is dropped on arrival.
! Enable snooping globally and for the VLAN, then trust the uplink S1(config)# ip dhcp snooping S1(config)# ip dhcp snooping vlan 10 S1(config)# interface gigabitethernet0/1 S1(config-if)# ip dhcp snooping trust S1(config-if)# exit ! Optionally bound the rate on untrusted ports S1(config)# interface fastethernet0/2 S1(config-if)# ip dhcp snooping limit rate 10 S1(config-if)# exit S1# show ip dhcp snooping binding MacAddress IpAddress Lease(sec) Type VLAN Interface ------------------ --------------- ---------- ------------- ---- ----------------- 00:50:79:66:68:00 192.168.10.50 86215 dhcp-snooping 10 FastEthernet0/2
The binding table is the crown: every other Layer-2 security feature reuses it. DAI checks ARP responses against it, and IP Source Guard (a related feature) filters data packets using it. Because DAI needs the table, DAI is effectively a downstream consumer of DHCP snooping — on the exam, a question that turns on DAI quietly assumes snooping is already on.
Dynamic ARP Inspection (DAI)
ARP is stateless and unauthenticated, which allows ARP poisoning: an attacker replies to a victim’s ARP request claiming “I am the gateway”, redirecting traffic through their device — a classic man-in-the-middle. DAI validates every ARP packet against the DHCP snooping binding table. If the sender’s MAC and IP in the ARP frame disagree with the binding entry for that port and VLAN, the packet is dropped (and optionally logged).
S1(config)# ip arp inspection vlan 10 S1(config)# interface gigabitethernet0/1 S1(config-if)# ip arp inspection trust S1(config-if)# exit S1# show ip arp inspection interfaces
Like DHCP snooping, DAI uses trusted vs untrusted ports: trusted ports (toward the core/gateway) are assumed to send valid ARP; untrusted ports (client-facing) get full validation (source and destination MAC/IP checks). A poisoned ARP reply arriving on an untrusted port never reaches the victim, so the impersonation fails at the wire.
802.1X port-based authentication
802.1X authenticates the device before the port will pass traffic. Three roles cooperate:
- Supplicant — the client asking for access; runs 802.1X software (built into Windows, macOS, and many operating systems).
- Authenticator — the switch, which blocks the port into an unauthorized state until success. Unauthorized ports typically only carry EAP frames.
- Authentication server — usually a RADIUS server (Lesson 11) that receives the credentials via EAP and answers accept/reject.
Installing 802.1X makes the network port behave like a door with an ID check: no valid credential, no traffic — not even DHCP. Guests without 802.1X software typically land in a segregated guest VLAN instead, so the feature is about enforcement, not just authentication. On the exam, remember which device is which (supplicant = client, authenticator = switch, server = RADIUS) and that the port stays blocked until the server says accept.
BPDU guard and root guard
Spanning Tree Protocol trusts any switch that sends BPDUs, which lets a rogue device become the root bridge and pull the whole topology through it. Two protections are port-level and closely related but not identical:
| Feature | What it blocks | Default action |
|---|---|---|
| BPDU guard | Any BPDUs on an access port (indicating a rogue/bridged device or loop) | Port is err-disabled (usually via spanning-tree bpduguard) |
| Root guard | A port becoming / propagating a better root | Port is put into root-inconsistent state; traffic still flows but BPDUs from that port are ignored |
! BPDU guard: shutdown a port that receives any BPDU (access ports) S1(config)# interface fastethernet0/24 S1(config-if)# spanning-tree bpduguard enable S1(config-if)# exit ! Root guard: never let this port become (or forward) a superior root S1(config)# interface fastethernet0/23 S1(config-if)# spanning-tree guard root S1(config-if)# exit
portfast for immediate access-port forwarding, and BPDU guard to defend
those fast ports.
Storm control
A broadcast storm — runaway broadcast/multicast frames caused by a loop or a broken driver — can saturate a link and starve legitimate traffic. Storm control sets a ceiling (as a percentage of bandwidth or a rate of packets-per-second) on broadcast, multicast, and unknown-unicast traffic per port. Traffic above the ceiling is dropped, and the switch can be told to log or even shut the port down.
S1(config)# interface fastethernet0/24 S1(config-if)# storm-control broadcast level 50 S1(config-if)# storm-control multicast level 50 S1(config-if)# storm-control action shutdown S1(config-if)# end S1# show storm-control broadcast
The threshold is a percentage of the link speed. Dropping frames above the ceiling is the normal
operation; the shutdown action escalates a sustained storm to err-disable, forcing
attention. In a design sense, storm control is the documentation that loops are a Layer 2 hygiene
problem — it contains the damage while you fix the root cause.
The vocabulary you need
Every term below appears in the lesson text above. Select one to read its definition, then use the quiz at the end to check what stuck.
Review
Check what you have learned with these review questions.
Sources & references
- Cisco. CCNA (200-301) Exam Topics. cisco.com.
- IETF. Request for Comments (RFCs). rfc-editor.org.
- IANA. Internet Assigned Numbers Authority registries. iana.org.
Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.