Lesson 3 — Layer 2 Security Controls and Common Attacks
Week 7 outline
- Week 7 overview
- Lesson 1Standard and Extended ACLs
- Lesson 2Device Access and Management-Plane Hardening
- QuizACLs & Device Hardening
- Lesson 3Layer 2 Security Controls and Common Attacks (current step)
- Lesson 4Security Program Fundamentals
- QuizLayer 2 Security & the Security Program
- CheckpointWeek 7 Checkpoint
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
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

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 | What it does | Control |
|---|---|---|
| MAC flooding / extra devices | Floods the MAC table, or attaches a rogue hub or AP so one port carries many MACs | Port security — limit MACs per port |
| Rogue DHCP server | Hands out an attacker gateway and DNS — a man-in-the-middle | DHCP snooping — drop server replies on untrusted ports |
| ARP spoofing / poisoning | Maps the victim's IP to the attacker's MAC — Layer 2 MITM | Dynamic ARP Inspection — validate ARP against bindings |
| Rogue switch / STP manipulation | Injects BPDUs to become root or create a loop | BPDU Guard and Root Guard |
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.
| Mode | Behaviour | Port state |
|---|---|---|
| shutdown (default) | Err-disable the port; all traffic blocked until recovery | down (err-disabled) |
| restrict | Drop violating frames, log, increment the violation counter | up |
| protect | Drop violating frames silently — no log, no counter | up |
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.
| Guard | Where it goes | On receiving the offending BPDU | Recovery |
|---|---|---|---|
| BPDU Guard | Portfast access ports | Err-disables the port — a user port should never see a BPDU, so one means someone plugged in a switch | Manual (shutdown / no shutdown), or errdisable recovery |
| Root Guard | Ports facing downstream switches | Moves the port to root-inconsistent, blocking traffic, so the downstream switch cannot become root | Automatic 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
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 shutdownPort 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.
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.
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?
See it happen
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
