White Belt: Layer 2 Security: Port Security, DHCP Snooping & DAI
Most attacks that start inside a building start at Layer 2: a rogue DHCP server, a spoofed ARP reply, an unmanaged switch plugged into a wall jack. Three features that ship on every Catalyst switch stop the common cases. This lesson configures all three on IOS XE and shows you how to prove they are working.
The three threats, and the feature for each
| Threat | What happens | Fix |
|---|---|---|
| Rogue device or MAC flood | Someone plugs in a hub or switch, or floods the CAM table so the switch starts flooding unicast traffic to every port. | Port security: limit how many MAC addresses a port will learn. |
| Rogue DHCP server | A misconfigured home router, or an attacker, hands out addresses and a malicious default gateway or DNS server. | DHCP snooping: only trusted ports may send DHCP server messages. |
| ARP spoofing | An attacker answers ARP requests for the gateway with their own MAC and sits in the middle of every conversation. | Dynamic ARP Inspection (DAI): ARP replies are checked against the DHCP snooping binding table. |
They build on each other. DHCP snooping produces a table of which IP and MAC live on which port; DAI uses that table to judge ARP packets. Turn them on in that order.
1 · Port security
Switch(config)# interface range Gi1/0/1 - 24
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan 10
Switch(config-if-range)# switchport port-security
Switch(config-if-range)# switchport port-security maximum 2
Switch(config-if-range)# switchport port-security violation restrict
Switch(config-if-range)# switchport port-security mac-address sticky
Switch(config-if-range)# switchport port-security aging time 10
Switch(config-if-range)# switchport port-security aging type inactivity
Explanation: each user port learns at most two MAC addresses (a PC behind an IP phone is the usual reason for two). sticky writes learned addresses into the running config so a reboot does not forget them. violation restrict drops frames from any extra address and increments a counter, without taking the port down; shutdown (the default) err-disables the port, which generates more helpdesk calls than it stops attacks.
Tip: err-disable recovery
If you do use violation shutdown, add errdisable recovery cause psecure-violation and errdisable recovery interval 300 globally so a port comes back on its own after five minutes.
2 · DHCP snooping
Switch(config)# ip dhcp snooping
Switch(config)# ip dhcp snooping vlan 10,20
Switch(config)# no ip dhcp snooping information option
Switch(config)# interface Gi1/0/48
Switch(config-if)# description Uplink to core
Switch(config-if)# ip dhcp snooping trust
Switch(config-if)# exit
Switch(config)# interface range Gi1/0/1 - 24
Switch(config-if-range)# ip dhcp snooping limit rate 15
Explanation: once snooping is on for a VLAN, DHCP server messages (OFFER, ACK, NAK) are only accepted on trusted ports. Your uplinks toward the real DHCP server are trusted; every user port is untrusted by default. The rate limit stops a client from flooding DISCOVERs. no ip dhcp snooping information option matters on most networks: by default the switch inserts Option 82 into relayed requests, and a DHCP server that is not expecting it will drop them.
3 · Dynamic ARP Inspection
Switch(config)# ip arp inspection vlan 10,20
Switch(config)# ip arp inspection validate src-mac dst-mac ip
Switch(config)# interface Gi1/0/48
Switch(config-if)# ip arp inspection trust
Switch(config-if)# exit
Switch(config)# interface range Gi1/0/1 - 24
Switch(config-if-range)# ip arp inspection limit rate 15
Explanation: on untrusted ports, every ARP packet is checked against the DHCP snooping binding table. A reply claiming an IP that was never leased to that MAC on that port is dropped and logged. Trust the uplinks for the same reason as before. The validate options add sanity checks on the Ethernet and ARP headers.
Static-IP devices break DAI
A printer with a static address has no DHCP binding, so its ARP replies fail inspection. Either give it a DHCP reservation, or add it to an ARP ACL: arp access-list STATICS → permit ip host 10.10.10.50 mac host 0011.2233.4455 → ip arp inspection filter STATICS vlan 10.
Verify
Switch# show port-security interface Gi1/0/5
Port Security : Enabled
Port Status : Secure-up
Violation Mode : Restrict
Maximum MAC Addresses : 2
Total MAC Addresses : 1
Security Violation Count : 0
Switch# show ip dhcp snooping binding
MacAddress IpAddress Lease(sec) Type VLAN Interface
------------------ --------------- ---------- ------------- ---- --------------------
00:50:56:A1:B2:C3 10.10.10.23 86210 dhcp-snooping 10 GigabitEthernet1/0/5
Switch# show ip arp inspection vlan 10
Vlan Configuration Operation ACL Match Static ACL
---- ------------- --------- --------- ----------
10 Enabled Active
Switch# show ip arp inspection statistics vlan 10
The binding table is the heart of it. If a port shows no binding for a client that is clearly online, snooping is not seeing the lease: check that the VLAN is in the snooping list and that the uplink toward the DHCP server is trusted.
Try it: Layer 2 security
Configure port security, DHCP snooping and DAI on a simulated Catalyst 9300, then read the same show commands you saw above. Type ? for options, help for the full list, or paste the whole block from the examples above. It is a simulator, not a real device, so nothing you do here can break anything.
Suggested run:
enable
configure terminal
vlan 10
name Users
exit
ip dhcp snooping
ip dhcp snooping vlan 10
no ip dhcp snooping information option
ip arp inspection vlan 10
ip arp inspection validate src-mac dst-mac ip
interface Gi1/0/48
description Uplink to core
switchport mode trunk
ip dhcp snooping trust
ip arp inspection trust
exit
interface range Gi1/0/1 - 4
switchport mode access
switchport access vlan 10
switchport port-security
switchport port-security maximum 2
switchport port-security violation restrict
switchport port-security mac-address sticky
ip dhcp snooping limit rate 15
ip arp inspection limit rate 15
end
show port-security
show port-security interface Gi1/0/2
show ip dhcp snooping
show ip dhcp snooping binding
show ip arp inspection vlan 10
show running-config
Summary
- Port security limits MAC addresses per port; use
restrictunless you want err-disabled ports. - DHCP snooping trusts only uplinks for server messages and builds the binding table.
- DAI uses that table to drop spoofed ARP; trust the same uplinks, and ACL your static-IP devices.
- Verify with
show port-security,show ip dhcp snooping binding,show ip arp inspection.