MGMT · addressing · reviewed

DHCP

Dynamic Host Configuration Protocol

Lets a host with no address ask the network for one, along with the handful of parameters it needs to be useful.

Presenter modeEmbed this figure

Protocol SummaryRFC 2131 · DRAFT STANDARD · March 1997Client-server interaction - allocating a network addressRFC 2131 · DRAFT STANDARD · March 1997DHCP client behaviorRFC 2131 · DRAFT STANDARD · March 1997DHCP Message TypeRFC 2132 · DRAFT STANDARD · March 1997Relay Agent Information OptionRFC 3046 · PROPOSED STANDARD · January 2001

Why it exists

Every host on an IP network needs an address that is unique on its subnet, a mask, a gateway and a resolver. Assigning those by hand works until a person has to do it twice, and it fails completely for anything mobile — a laptop that moves between two buildings needs different values in each.

BOOTP solved the bootstrap half in 1985 with a static table mapping MAC addresses to addresses. DHCP keeps its message format, its ports and most of its header, and adds the part that matters: allocation from a pool, for a bounded time, that the client renews or loses. IntroductionRFC 2131 · DRAFT STANDARD · March 1997

The lease is the design. An address that expires means a network that reclaims addresses from devices that left without saying so, which is what makes a pool smaller than the population workable.

Four messages to get an address

A client with nothing broadcasts, hears an offer, asks for it by name, and is confirmed. The fourth message is what makes the lease exist.

The client has an interface that is up and no address on it. It cannot send a unicast, it does not know a gateway, and it does not know a server exists. Everything it can do has to be a broadcast. Client · no address: Address none, State INIT. Access switch. DHCP server A. DHCP server B.

Client · no addressAddress: noneState: INITAccess switchDHCP server ADHCP server Baccess
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
Client · no addresshostAddress: none · State: INIT
Access switchswitch
DHCP server Ahost
DHCP server Bhost
Client · no addressAccess switchlinkup · access
Access switchDHCP server Alinkup
Access switchDHCP server Blinkup
1 / 7

The client has an interface that is up and no address on it. It cannot send a unicast, it does not know a gateway, and it does not know a server exists. Everything it can do has to be a broadcast.

What changed

  • Client · no address: Address → none
  • Client · no address: State → INIT

How it works

Four messages: DISCOVER, OFFER, REQUEST, ACK. The first three are broadcast, because until the last one there is no agreed address to unicast to and, in the REQUEST, because the servers that were not chosen need to hear that they were not chosen. Client-server interaction - allocating a network addressRFC 2131 · DRAFT STANDARD · March 1997

The message type is option 53. The header carries only `op`, which distinguishes a request from a reply — a BOOTP field that survived because the format did. Almost everything a client actually receives is an option, and the fixed header is mostly there for compatibility. DHCP Message TypeRFC 2132 · DRAFT STANDARD · March 1997

A broadcast does not cross a router, so on any network with more than one subnet a relay agent forwards the message and writes its own interface address into giaddr. The server selects a scope by matching giaddr, which makes the relay — not the client and not the server — the thing that decides which subnet a host lands in. Protocol SummaryRFC 2131 · DRAFT STANDARD · March 1997

The lease runs on two timers. At T1, half the lease by default, the client unicasts a renewal to the server that granted it. At T2, seven eighths, it gives up on that server and broadcasts to any. Only when the lease itself expires does it stop using the address. Renewal (T1) Time ValueRFC 2132 · DRAFT STANDARD · March 1997

The options area is 312 octets in a minimum-sized message, and a relay adding option 82 spends part of a budget the scope’s author never saw. Overflow truncates silently. Option OverloadRFC 2132 · DRAFT STANDARD · March 1997

Try it

Assemble an option set

Pick the options a scope hands out and see the bytes, the total length, and where it overflows.

Options this scope hands out

68 of 312 octets used · 244 left

Encoded option set, in code order
CodeOptionValueLenWire
1Subnet Mask46
3Router46
6Domain Name Server810
15Domain Name1618
51IP Address Lease Time46
53DHCP Message Type13
54Server Identifier46
58Renewal (T1) Time Value46
59Rebinding (T2) Time Value46
255Endterminator01

Options area on the wire

01 04 ff ff ff 00 03 04 c0 a8 04 01 06 08 c0 a8 04 19 01 01 01 01 0f 10 6c 61 62 2e 61 6c 65 78 66 6c 75 78 2e 63 6f 6d 33 04 00 01 51 80 35 01 05 36 04 c0 a8 04 0a 3a 04 00 00 a8 c0 3b 04 00 01 27 50 ff
  • 1 · Subnet Mask If present it must appear before the Router option — RFC 2132 fixes the order for these two.
  • 6 · Domain Name Server Clients do not reliably fail over between these. A dead first resolver is a slow network, not an outage, which makes it hard to spot.
  • 15 · Domain Name A single domain. For a search list of several, option 119 is the correct one and this is not.
  • 58 · Renewal (T1) Time Value Defaults to half the lease.
  • 59 · Rebinding (T2) Time Value Defaults to 87.5% of the lease.

On the wire

Constructed examples, encoded from the field table below them — not captured traffic.

The client has no address, so it sends from 0.0.0.0 and every address field is zero. All it contributes is a transaction id and its MAC.

IPv4
A client with no address sends from 0.0.0.0 to 255.255.255.255. A relay or a renewing client unicasts. RFC 2131
UDP
Port 68 on the client, port 67 on the server or relay agent. RFC 2131
Fixed BOOTP portion
The 44 octets below, then sname (64) and file (128), then the magic cookie 63 82 53 63, then options. RFC 2131

Configure it

Relay DHCP from one client VLAN, sourcing giaddr from that VLAN’s own gateway.

Cisco IOS-XE 17.12 · Catalyst 9300, Catalyst 9500, ISR 4451draft

  1. interface Vlan30
     description Users
     ip address 198.51.100.1 255.255.255.0

    The gateway for the client VLAN. This address becomes giaddr, and therefore selects the scope, so it must be the one facing the clients.

    RFC 2131 §2

  2.  ip helper-address 192.0.2.10

    Turns the broadcast into a unicast toward the server and fills in giaddr from this interface. Configured under the client SVI, not under the interface facing the server.

    Common mistake: Putting the helper on the uplink or the management SVI. It still works, giaddr is still filled in, and every client gets an address from the wrong subnet.

    RFC 2131 §4.1

  3. interface Vlan40
     ip address 198.51.100.129 255.255.255.128
     ip helper-address 192.0.2.10

    One helper statement per client VLAN. Each supplies a different giaddr, which is how one server serves many subnets.

  4. ip dhcp relay information option

    Appends option 82 with the circuit and remote identifiers, so the server can see which port a request came from.

    Common mistake: Enabling this without checking the options budget. It is added on top of everything the scope sends, and the reply is what overflows.

    RFC 3046 §2.1

  5. ip dhcp snooping
    ip dhcp snooping vlan 30,40
    interface GigabitEthernet1/0/48
     ip dhcp snooping trust

    Drops server-class replies arriving on untrusted ports. Only the port toward the real server is trusted, which is the control against a host answering DISCOVER faster than the server.

Verify

show ip helper-address
Which interfaces relay, and to where.
show ip dhcp snooping binding
Learned bindings: MAC, address, lease, VLAN and port.
debug ip dhcp server packet detail
giaddr on the relayed request — the field that selects the scope.

Caveats

  • A helper address relays several UDP services, not only DHCP. `ip forward-protocol udp` controls which.
  • Option 82 insertion and DHCP snooping interact: a switch may drop relayed packets that already carry option 82 unless told to trust them.

When it breaks

Symptom first, because that is what you have when it happens.

  1. A client gets an address, but from the wrong subnet, with a gateway it cannot reach. The interface is up and everything looks configured.

    Narrow it down

    1. Capture at the server and read giaddr in the relayed DISCOVER.
    2. Compare it with the gateway address of the VLAN the client is actually in.
    3. Check which interface the helper or forwarder statement is configured under.

    Cause

    The relay sourced giaddr from the wrong interface, so the server matched the wrong scope. Both devices behaved correctly.

    Fix

    Configure the relay on the SVI facing the clients, one statement per client VLAN.

    Protocol SummaryRFC 2131 · DRAFT STANDARD · March 1997
  2. The client falls back to a link-local address and no lease appears anywhere.

    Narrow it down

    1. Confirm the port is in the VLAN you think it is, and that the VLAN reaches the relay.
    2. Check for a helper address on the client-facing SVI at all.
    3. Look for DHCP snooping dropping the request because the port is untrusted.
    4. Confirm the pool is not simply empty.

    Cause

    The broadcast never reached a server, or reached one with nothing to give. A missing relay statement and an exhausted pool present identically from the client.

    Fix

    Work outward from the client: VLAN, relay, reachability, then pool utilisation.

  3. An option configured in the scope never arrives. Common with boot filenames, so it presents as a PXE or TFTP fault.

    Narrow it down

    1. Capture the ACK and count the octets in the options area.
    2. Check whether a relay is inserting option 82 and how large it is.
    3. Confirm the client asked for the option in its parameter request list.

    Cause

    The reply exceeded the options area and was truncated, or the client never requested the option and the server omitted it.

    Fix

    Trim the scope to what clients request, enable option overload, or raise the message size. Removing options nobody asked for is usually enough.

    Parameter Request ListRFC 2132 · DRAFT STANDARD · March 1997
  4. Two hosts hold the same address. One or both lose connectivity intermittently as ARP entries flap.

    Narrow it down

    1. Look for DHCPDECLINE in the server log — the client that probed and found a conflict.
    2. Check whether a statically configured device sits inside the dynamic range.
    3. Check for a second DHCP server on the segment.

    Cause

    The pool overlaps something the server does not know about: a static address, or another allocator.

    Fix

    Exclude the static range from the pool, or convert the static addresses to reservations so the allocator can see them.

    DHCP client behaviorRFC 2131 · DRAFT STANDARD · March 1997
  5. Some clients get a plausible address and a gateway that is not the real one. Which clients are affected changes between reboots.

    Narrow it down

    1. Compare the server identifier in option 54 against the real server’s address.
    2. Trace the MAC in the offer back through the address table to a port.
    3. Check whether DHCP snooping is enabled and which ports are trusted.

    Cause

    Another device on the segment is answering DISCOVER. Whichever reply arrives first wins, so the outcome is a race.

    Fix

    Enable DHCP snooping and trust only the ports toward legitimate servers. Untrusted ports then have their server-class replies dropped.

Design notes

Lease length is a trade between churn and reclaim speed. Long leases mean stable addresses and slow recovery of a pool after an event; short leases mean the opposite plus more renewal traffic. A guest wireless network wants hours; a data centre wants days.

Reservations are better than static addresses for anything that must keep an address. A static address configured on the device is invisible to the server, which will eventually hand it to someone else; a reservation is the same outcome recorded where the allocator can see it.

Two servers with the same scope and no coordination will both allocate from it and eventually collide. Either split the pool between them — the classic 80/20 — or run a protocol that shares state. Splitting is simpler and loses only capacity.

DHCP has no authentication worth the name. A host on the segment can answer faster than the real server and become the gateway for everything that believed it. DHCP snooping on the access switch, permitting server replies only on the ports where a server actually is, is the control.

Misconceptions

The DHCP server decides which subnet a client belongs to.
The relay does. The server matches a scope against giaddr, which the relay wrote. A correctly configured server behind a misconfigured relay hands out correct addresses from the wrong subnet all day. Protocol SummaryRFC 2131 · DRAFT STANDARD · March 1997
Once the client has an offer, it replies directly to that server.
The initial REQUEST is broadcast. It has to be, so servers whose offers were declined can release the addresses they reserved. Renewals at T1 are unicast — those are a different message in a different state. Client-server interaction - allocating a network addressRFC 2131 · DRAFT STANDARD · March 1997
When a lease expires the client loses its address.
Long before that. The client renews at half the lease and again at seven eighths; reaching expiry means every renewal failed. A client that lost its address did not have a lease problem, it had a reachability problem for at least half a lease. Rebinding (T2) Time ValueRFC 2132 · DRAFT STANDARD · March 1997
siaddr is the address of the DHCP server.
It is the next server in a bootstrap sequence — a TFTP server, in practice. The DHCP server identifies itself in option 54. Reading siaddr as the server identifier is a routine cause of PXE clients trying to boot from 0.0.0.0. Protocol SummaryRFC 2131 · DRAFT STANDARD · March 1997

More walkthroughs

The relay picks the subnet, and picks it wrongfailure

A client gets an address from a scope that does not belong to its VLAN. The server did exactly what it was told; what it was told came from giaddr.

The client is in VLAN 30, which should get 198.51.100.0/24. The gateway holds an interface in every VLAN and relays DHCP to a server two hops away. Client · VLAN 30. Access switch. L3 gateway: VLAN 30 SVI 198.51.100.1. DHCP server: Scopes 192.0.2.0/24, 198.51.100.0/24.

Client · VLAN 30Access switchL3 gatewayVLAN 30 SVI: 198.51.100.1DHCP serverScopes: 192.0.2.0/24, 198.51.100.0/24access 30trunkrouted
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
Client · VLAN 30host
Access switchswitch
L3 gatewayrouterVLAN 30 SVI: 198.51.100.1
DHCP serverhostScopes: 192.0.2.0/24, 198.51.100.0/24
Client · VLAN 30Access switchlinkup · access 30
Access switchL3 gatewaylinkup · trunk
L3 gatewayDHCP serverlinkup · routed
1 / 6

The client is in VLAN 30, which should get 198.51.100.0/24. The gateway holds an interface in every VLAN and relays DHCP to a server two hops away.

What changed

  • L3 gateway: VLAN 30 SVI → 198.51.100.1
  • DHCP server: Scopes → 192.0.2.0/24, 198.51.100.0/24

The options area runs outdesign-choice

A scope grows one option at a time until the boot filename stops arriving. Nothing errors; the message simply has no room left.

A client must accept a 576-octet message. Take off the IP and UDP headers, the 236-octet fixed portion and the four-octet magic cookie, and 312 octets are left for every option the scope hands out. PXE client. Relay agent. DHCP server: Options budget 312 octets.

PXE clientRelay agentDHCP serverOptions budget: 312 octets
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
PXE clienthost
Relay agentrouter
DHCP serverhostOptions budget: 312 octets
PXE clientRelay agentlinkup
Relay agentDHCP serverlinkup
1 / 6

A client must accept a 576-octet message. Take off the IP and UDP headers, the 236-octet fixed portion and the four-octet magic cookie, and 312 octets are left for every option the scope hands out.

What changed

  • DHCP server: Options budget → 312 octets

Terms

Lease
A binding between a client and an address, valid for a stated time. The client renews at half the lease and again at seven eighths; reaching expiry means every renewal failed.
Relay agent
A router that forwards DHCP between a client broadcast domain and a server elsewhere, recording the interface it came from in giaddr.
giaddr
The relay agent address field. The server matches it against its scopes, so this one field decides which subnet a client is allocated from.
Scope
A server-side pool of addresses for one subnet, with the options that go with it. Selected by giaddr, not by anything the client says.
Option overload
Option 52, which declares that the sname and file header fields carry options instead of their usual contents — 192 extra octets when the 312-octet options area is full.

Check yourself

  • Where does a DHCP message say whether it is a DISCOVER or a REQUEST?
  • What does a DHCP server use to choose which scope to allocate from?
  • Two servers offer an address. How does the one that loses find out?
  • A client holds an 8-hour lease. When does it first try to renew?
  • A scope defines option 42 for NTP but clients never receive it. Most likely cause?
  • A scope sends both option 3 (Router) and option 121 (Classless Static Route). What does a compliant client do?
  • A client completes DORA, then immediately sends DHCPDECLINE and starts over. What did it find?
  • How does a server’s reply find its way back to a relayed client?