// Lesson 42 of 49 · Security fundamentals
Port security, DHCP snooping and Dynamic ARP Inspection
The access layer is where untrusted devices plug in. Three switch features stop the most common Layer 2 attacks.
Port security
Limits which and how many MAC addresses may use a port — defeating MAC flooding and casual device swaps.
SW1(config)# interface GigabitEthernet1/0/5
SW1(config-if)# switchport mode access
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 restrict
- Port security works only on access (or trunk) ports that are statically set — not on dynamic DTP ports.
- Sticky learns the connected MACs and writes them into the running config.
| Violation mode | Drops offending traffic | Logs / counts | Disables the port |
|---|---|---|---|
| shutdown (default) | Yes | Yes | Yes — err-disabled |
| restrict | Yes | Yes | No |
| protect | Yes | No | No |
SW1# show port-security interface GigabitEthernet1/0/5
SW1# show port-security address
SW1# show interfaces status err-disabled
Recover a shut-down port with shutdown then no shutdown, or automatically:
SW1(config)# errdisable recovery cause psecure-violation
SW1(config)# errdisable recovery interval 300
DHCP snooping
Classifies ports as trusted (towards the real DHCP server) or untrusted (everything else). DHCP server messages (Offer, Ack) arriving on untrusted ports are dropped, so a rogue DHCP server cannot hand out a malicious gateway.
SW1(config)# ip dhcp snooping
SW1(config)# ip dhcp snooping vlan 10,20
SW1(config)# no ip dhcp snooping information option ! often needed when the server is a router/relay that rejects option 82
SW1(config)# interface GigabitEthernet1/0/24
SW1(config-if)# ip dhcp snooping trust ! uplink towards the DHCP server
SW1(config)# interface range GigabitEthernet1/0/1 - 20
SW1(config-if-range)# ip dhcp snooping limit rate 10 ! DHCP packets per second
Snooping also builds a binding table (MAC, IP, VLAN, port, lease):
SW1# show ip dhcp snooping
SW1# show ip dhcp snooping binding
Dynamic ARP Inspection (DAI)
Checks ARP packets on untrusted ports against the DHCP snooping binding table. An ARP claiming an IP/MAC pair that DHCP never handed to that port is dropped — stopping ARP spoofing and man-in-the-middle attacks.
SW1(config)# ip arp inspection vlan 10,20
SW1(config)# interface GigabitEthernet1/0/24
SW1(config-if)# ip arp inspection trust
SW1# show ip arp inspection
Devices with static IP addresses have no binding, so DAI would drop their ARPs — add them with an ARP ACL or static bindings first.
Order of deployment
- Port security on access ports.
- DHCP snooping (trust uplinks, verify the binding table fills).
- DAI on the same VLANs (handle static hosts first).
Key points
- Port security: maximum MACs, sticky learning, violation shutdown/restrict/protect.
- DHCP snooping: trust only ports towards real DHCP servers; it builds the binding table.
- DAI uses that binding table to drop forged ARP replies.
- err-disabled ports need manual or automatic recovery.
Sign in to save your lesson progress across devices. You can read every published lesson without an account.