PracticeLabs
Week 7Lesson 3Required57 min estimated0% progress

Layer 2 Security Controls and Common Attacks

Defend the access-layer switch — configure port security with sticky MACs and a violation mode, layer DHCP snooping, DAI, and BPDU Guard on top, and recover an err-disabled port — matching each control to the attack it stops.

Lesson orientation

What you'll learn (5 objectives)~57 min: video → lesson → check → apply → lab prep

Learning objectives

  • Map each access-layer attack to the control that mitigates it
  • Configure port security with a MAC maximum, sticky learning, and a violation mode, knowing the defaults are maximum 1 and shutdown
  • Distinguish the protect, restrict, and shutdown violation modes and recover an err-disabled port
  • Explain DHCP snooping trusted versus untrusted ports and why DAI depends on the snooping binding table
  • Explain where BPDU Guard and Root Guard apply and what each protects against

Terms you will see

Port securitySticky MACViolation modeerr-disabledDHCP snoopingTrusted / untrusted portBinding tableDynamic ARP InspectionBPDU GuardRoot Guardroot-inconsistent

Time breakdown

  • Read the notes25 min
  • Walk the port-security configuration and output13 min
  • Diagnose the err-disabled port11 min
  • Work the DAI troubleshooting scenario8 min

Assigned video

Opens on YouTube
Recommended video

Port Security (Day 49)

By Jeremy's IT Lab · Opens externally on YouTube

Assigned watch
~8 min

Where to stop

DHCP snooping, DAI, and BPDU Guard are covered in the written sections, not in this video.

The source marks this segment timestampStatus="unresolved" with no start or end, so no bounds are shown here.

The link opens in a new browser tab. Return here when you finish watching.

Watch for these concepts

  • How sticky learning captures the first MAC
  • How maximum limits devices, and how a violation err-disables the port

Go beyond the video

The assigned video introduces the idea. CCNA Practice Labs completes the learning path: clarify core concepts, explore how each device behaves, visualize the communication path, check your understanding, and prepare for hands-on lab work.

Watch the concept → understand it → visualize it → practice it → apply it.

Four attacks, four controls

The access-layer switch is where end users — and attackers — plug in. Because a switch trusts whatever MAC, DHCP reply, or ARP it hears by default, the access port is the softest target in the network. Access-layer security is easiest to hold as attack-and-mitigation pairs.

Attack to control
AttackWhat it doesControl
MAC flooding / extra devicesFloods the MAC table, or attaches a rogue hub or AP so one port carries many MACsPort security — limit MACs per port
Rogue DHCP serverHands out an attacker gateway and DNS — a man-in-the-middleDHCP snooping — drop server replies on untrusted ports
ARP spoofing / poisoningMaps the victim's IP to the attacker's MAC — Layer 2 MITMDynamic ARP Inspection — validate ARP against bindings
Rogue switch / STP manipulationInjects BPDUs to become root or create a loopBPDU Guard and Root Guard
Port security is a device-count limit, not an identity check
Layer 2 has no strong identity to begin with — a source MAC is just a field the host writes into the frame, so "only this exact MAC may use the port" is defeated the moment an attacker copies the allowed address. What an attacker cannot easily fake is *count*: running a rogue switch or AP behind the desk requires multiple MACs visible on the port. Capping the maximum is what makes that misuse trip immediately. Understand port security as a device-count limit, backed by 802.1X when you need genuine authentication.

Maximum, sticky learning, and the three violation modes

Two knobs shape port security. Maximum sets how many source MACs the port accepts — the default is 1, and a phone-plus-PC port needs 2. Sticky learning writes the live MAC into the running-config so you do not type addresses by hand, but you must copy run start or a reload loses it.

Violation modes — only one takes the port down
ModeBehaviourPort state
shutdown (default)Err-disable the port; all traffic blocked until recoverydown (err-disabled)
restrictDrop violating frames, log, increment the violation counterup
protectDrop violating frames silently — no log, no counterup
The default combination is the outage
The default maximum is 1 and the default violation mode is shutdown. Enable switchport port-security on a port with an IP phone and a PC behind it and nothing else, and the phone's MAC is learned first, the PC's MAC becomes the second address, that exceeds the maximum, and the port err-disables the instant the PC transmits. If a design does not state a maximum, assume 1 — and a phone-plus-PC port must be set to 2. This is the most common port-security outage there is.

Recovering an err-disabled port is a manual shutdown then no shutdown after removing the offending device — a plain no shutdown alone does not clear err-disabled. You can also arm auto-recovery with errdisable recovery cause psecure-violation and an interval.

DHCP snooping, DAI, and the two STP guards

A rogue DHCP server on a user VLAN can answer a client's DISCOVER faster than the real server and hand out the attacker's box as the default gateway. DHCP snooping classifies every port as trusted or untrusted.

  • Trusted ports are the uplinks toward the legitimate DHCP server or other switches — server messages such as OFFER and ACK are allowed to enter here.
  • Untrusted ports are end-user access ports, where DHCP server messages are dropped. A client on an untrusted port may still send DISCOVER and REQUEST; it simply cannot masquerade as a server.
  • As snooping watches legitimate leases it builds a binding table of MAC to IP to VLAN to port. Enable it globally and per VLAN, and mark trusted ports consistently on every switch in the path.
DAI is only as good as the binding table beneath it
Dynamic ARP Inspection compares each ARP packet on an untrusted port against the DHCP snooping binding table; if the sender's IP, MAC, and VLAN do not match a valid binding, the ARP is dropped, defeating ARP poisoning. The exam-critical dependency follows directly: DAI needs DHCP snooping enabled on the same VLANs, because the binding table is the only thing it has to validate against. Like snooping, DAI is not performed on trusted ports. Statically addressed hosts have no snooping binding, so they need an ARP ACL or a static binding or DAI will drop their ARP too.
BPDU Guard and Root Guard — related, but not the same response
GuardWhere it goesOn receiving the offending BPDURecovery
BPDU GuardPortfast access portsErr-disables the port — a user port should never see a BPDU, so one means someone plugged in a switchManual (shutdown / no shutdown), or errdisable recovery
Root GuardPorts facing downstream switchesMoves the port to root-inconsistent, blocking traffic, so the downstream switch cannot become rootAutomatic once the superior BPDUs stop

Access ports usually run Portfast to skip STP's listening and learning delay, and BPDU Guard is what makes that safe. Apply BPDU Guard to access ports, never to core trunks — a trunk is supposed to carry BPDUs.

Configure sticky port security and read the verification

Fa0/5 — user access port in VLAN 20, phone plus PC
SW1(config)# interface FastEthernet0/5
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
SW1(config-if)# switchport port-security
SW1(config-if)# switchport port-security maximum 2
SW1(config-if)# switchport port-security mac-address sticky
SW1(config-if)# switchport port-security violation shutdown
show port-security interface FastEthernet0/5
Port Security              : Enabled
Port Status                : Secure-up
Violation Mode             : Shutdown
Maximum MAC Addresses      : 2
Total MAC Addresses        : 1
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 1
Last Source Address:Vlan   : 0025.83ab.cd01:20
Security Violation Count   : 0
  • Port Status Secure-up means security is active and the port is forwarding. A violation in shutdown mode would read Secure-shutdown instead.
  • Maximum 2 with Total 1 shows headroom for the PC after the phone was learned.
  • Sticky MAC Addresses : 1 confirms sticky learning captured an address, and show running-config now carries a matching switchport port-security mac-address sticky line — save it with copy run start.
  • Security Violation Count is the counter that climbs under restrict and shutdown when an extra MAC appears, and stays at zero under protect.
  • switchport mode access matters: port security is only supported on a static access or voice port, not on a dynamically negotiated one.
Troubleshooting — DAI took the VLAN down
Symptom: after enabling ip arp inspection vlan 10, users on VLAN 10 lose their default gateway and each other, though DHCP snooping was "turned on". Diagnosis: show ip dhcp snooping reveals snooping is enabled globally but not for VLAN 10, so there is no binding table for that VLAN — and DAI with nothing to validate against drops every ARP on untrusted ports, including legitimate ARP to the gateway. show ip arp inspection statistics shows the drop counter climbing. A second contributor to check is the router-facing uplink, which was never marked ip arp inspection trust, so even valid gateway ARP is inspected. Fix: enable ip dhcp snooping vlan 10 and let clients rebuild bindings, add static bindings for statically addressed hosts, then trust the uplink toward the router.

What you should retain

  • Port security limits source MACs per access port; the defaults are maximum 1 and violation shutdown.
  • Sticky learning writes the live MAC into the running-config — copy run start or a reload loses it.
  • Violation modes: protect drops silently, restrict drops and logs and counts, shutdown err-disables and is the default.
  • Recovering an err-disabled port takes shutdown then no shutdown, after removing the offending device.
  • DHCP snooping drops rogue server replies on untrusted ports and builds the binding table; trust the uplinks.
  • DAI validates ARP against that binding table, so it requires DHCP snooping on the same VLANs.
  • BPDU Guard err-disables a Portfast access port that receives a BPDU and needs manual recovery; Root Guard moves a port to root-inconsistent and recovers by itself once the superior BPDUs stop.
Pause and predictNot scored — nothing is recorded

Before you read on

A user calls: their PC lost the network right after they plugged the desk phone into "the little switch they brought from home". show interfaces status shows Fa0/5 err-disabled; show port-security interface Fa0/5 shows Violation Count 1 and Port Status Secure-shutdown. What happened, and what are the steps to fix it correctly?

Interactive tool
Optional~8 min

Flashcards

Drill the attack-to-control pairings, the three violation modes, and the defaults of maximum 1 and shutdown, until the DAI-needs-snooping dependency comes back without reconstruction.

Section quiz follows Lesson 4, once the human layer has joined the technical controls.

Study deeper

Topic guides extend this lesson — they do not replace the first-party walkthrough above.

Switch Security

For the fuller port-security reference, the DHCP snooping and DAI trust rules, and the verification and recovery command set