DHCP Snooping
Introduction and Basic Concepts
- Concept: DHCP Snooping is a Layer 2 security feature on Cisco switches that filters and inspects DHCP messages to protect against DHCP-based attacks.
- Details:
- Only filters DHCP messages; non-DHCP traffic is completely unaffected.
- Operates based on port trust states: Trusted vs. Untrusted.
Trusted vs. Untrusted Ports
- Untrusted Ports:
- Default state for all switch interfaces.
- Typically downlink ports facing end-user devices (PCs, wireless APs).
- All incoming DHCP messages are inspected. Malicious or invalid messages are dropped.
- Trusted Ports:
- Must be manually configured.
- Typically uplink ports facing network infrastructure (DHCP servers, relay agents, other switches).
- DHCP messages are forwarded without inspection.
graph LR
PC1[PC 1] -->|Untrusted| SW1
PC2[PC 2] -->|Untrusted| SW1
SW1 -->|Trusted| SW2
SW2 -->|Trusted| R1[DHCP Server]
Things to note: You must explicitly configure uplink ports as trusted; otherwise, legitimate DHCP server responses (OFFER, ACK) will be dropped by the switch.
DHCP-Based Attacks Prevented
DHCP Starvation (Exhaustion)
- Concept: An attacker floods the DHCP server with spoofed DHCP Discover messages using fake MAC addresses.
- Goal: Exhaust the DHCP server’s IP address pool, causing a Denial of Service (DoS) for legitimate clients.
- Mechanism: Attackers spoof the CHADDR (Client Hardware Address) field in the DHCP message.
DHCP Poisoning (Rogue DHCP Server)
- Concept: An attacker sets up a spurious (illegitimate) DHCP server on the local network.
- Goal: Perform a Man-in-the-Middle (MitM) attack.
- Mechanism:
- The rogue server responds to client DHCP Discover messages with a DHCP Offer.
- The rogue server assigns a valid IP but sets the Default Gateway and DNS to the attacker’s IP.
- Clients accept the first Offer received (often the attacker’s, as it is on the local LAN and requires no routing).
- All external traffic from the victim is routed through the attacker, who can inspect or modify it before forwarding it to the legitimate gateway.
DHCP Message Types
DHCP Snooping differentiates between messages sent by servers and clients to apply filtering rules.
| Message Type | Sender | Description | Snooping Action on Untrusted Port |
|---|---|---|---|
| DISCOVER | Client | Client seeks a DHCP server. | Inspected (MAC vs CHADDR check) |
| REQUEST | Client | Client requests offered IP. | Inspected (MAC vs CHADDR check) |
| RELEASE | Client | Client relinquishes IP lease. | Inspected (Binding table check) |
| DECLINE | Client | Client declines offered IP. | Inspected (Binding table check) |
| OFFER | Server | Server offers an IP address. | Always Discarded |
| ACK | Server | Server acknowledges/assigns IP. | Always Discarded |
| NAK | Server | Server declines client request. | Always Discarded |
Things to note: DHCP server messages (OFFER, ACK, NAK) are always discarded if received on an untrusted port. Only trusted ports should receive these.
DHCP Snooping Operations & Filtering Rules
When a DHCP message arrives on an untrusted port, the switch applies the following rules:
- Server Messages (OFFER, ACK, NAK):
- Action: Immediately discard.
- Client Messages (DISCOVER, REQUEST):
- Check: Compare the Ethernet frame’s Source MAC address with the DHCP message’s CHADDR (Client Hardware Address) field.
- Action: If they match -> Forward. If they mismatch -> Discard.
- Note: Protects against CHADDR spoofing (though attackers can bypass this by spoofing both the frame MAC and the CHADDR).
- Client Messages (RELEASE, DECLINE):
- Check: Compare the packet’s Source IP and Receiving Interface against the DHCP Snooping Binding Table.
- Action: If they match -> Forward. If they mismatch -> Discard.
- Note: Prevents attackers from sending RELEASE/DECLINE messages on behalf of other hosts to sever their network connectivity.
DHCP Snooping Binding Table
- Concept: A database dynamically built by the switch tracking legitimate DHCP leases.
- Details: Created when a client successfully completes the DORA (Discover, Offer, Request, Ack) process.
- Fields Stored: MAC Address, IP Address, Lease Time, VLAN ID, Interface ID.
- Fields NOT Stored: Default Gateway, Subnet Mask.
Rate Limiting
- Concept: Limits the rate at which DHCP messages are allowed to enter an interface to prevent DHCP Starvation attacks.
- Details:
- Configured in packets per second (pps).
- If the limit is exceeded, the interface is placed in an
err-disabledstate. - Recovery:
- Manual:
shutdownfollowed byno shutdown. - Automatic: Configure
errdisable recovery.
- Manual:
Things to note: Setting the limit too low (e.g., 1 pps) will cause legitimate DHCP traffic to trigger the err-disabled state. Choose a realistic value for production environments.
Option 82 (DHCP Relay Agent Information Option)
- Concept: A DHCP option that inserts information about the relay agent (switch ID, interface, VLAN) into the DHCP message.
- The Problem:
- By default, Cisco switches append Option 82 to DHCP client messages.
- If a switch receives a DHCP message with Option 82 on an untrusted port, it drops the message.
- If a non-relay switch adds Option 82 and forwards it to a DHCP server (like a router), the server may drop it due to “inconsistent relay information.”
- The Solution: Disable Option 82 insertion if the switch is purely Layer 2 and not acting as a DHCP relay agent.
Configuration Steps
- Enable DHCP Snooping globally.
- Enable DHCP Snooping per VLAN.
- Disable Option 82 (if not using relay agents).
- Configure uplink interfaces as trusted.
- (Optional) Configure rate limiting on downlink interfaces.
! Enable globally
SW1(config)# ip dhcp snooping
! Enable for specific VLANs
SW1(config)# ip dhcp snooping vlan 1
! Disable Option 82 insertion
SW1(config)# no ip dhcp snooping information option
! Configure trusted uplink interface
SW1(config)# interface GigabitEthernet0/0
SW1(config-if)# ip dhcp snooping trust
! Configure rate limiting on untrusted downlink interface
SW1(config)# interface GigabitEthernet0/1
SW1(config-if)# ip dhcp snooping limit rate 15
! Enable errdisable recovery for rate limiting
SW1(config)# errdisable recovery cause dhcp-rate-limit
Verification Commands
! View the DHCP snooping binding table
SW1# show ip dhcp snooping binding
! View DHCP snooping configuration and statistics per interface
SW1# show ip dhcp snooping
! View errdisable recovery status and timers
SW1# show errdisable recovery
Command Summary
Here is a consolidated list of all commands covered:
! Global Configuration
ip dhcp snooping
ip dhcp snooping vlan [vlan-list]
no ip dhcp snooping information option
errdisable recovery cause dhcp-rate-limit
! Interface Configuration
ip dhcp snooping trust
ip dhcp snooping limit rate [packets-per-second]
! Verification
show ip dhcp snooping binding
show ip dhcp snooping
show errdisable recovery