Sub topic 15
DHCPv6 and when to use it
This chapter covers what DHCPv6 adds to SLAAC, how a client and server exchange messages, and how to decide whether a network needs it. It assumes you know how SLAAC and Router Advertisements work, that you can read IPv6 prefixes, and that you have used DHCP on IPv4.
What DHCPv6 does that SLAAC does not
SLAAC lets a host build its own address from a prefix in a Router Advertisement (RA) plus an interface identifier. That works well, but the network has little control. It cannot tell which host has which address, and an RA cannot carry much beyond the prefix, the gateway, and optionally DNS servers.
DHCPv6 is the stateful alternative. A server keeps a lease table and hands out:
- Addresses, in a container called an IA_NA (Identity Association for Non-temporary Addresses).
- Delegated prefixes, in an IA_PD (Identity Association for Prefix Delegation). A home router uses this to get a /56 or /60 from its ISP.
- Options such as DNS servers, search domains, NTP servers, and boot file URLs.
DHCPv6 is not a drop-in copy of DHCPv4. It never supplies a default gateway, because routers announce themselves only through RAs. It also does not supply a prefix length for an address. The client learns that from the on-link prefix in the RA.
How RA flags select the mode
A router tells hosts which method to use with flags in its RA. The M and O flags are in the RA header. The A flag is in each Prefix Information option.
| M flag | O flag | A flag on prefix | Host behavior |
|---|---|---|---|
| 0 | 0 | 1 | SLAAC only. Nothing else is requested. |
| 0 | 1 | 1 | SLAAC for the address, stateless DHCPv6 for DNS and other options. |
| 1 | any | 1 | SLAAC address plus a DHCPv6 address. The host has both. |
| 1 | any | 0 | DHCPv6 address only. SLAAC is disabled for that prefix. |
The M flag means "Managed": ask a DHCPv6 server for an address. The O flag means "Other": ask for other configuration only. The flags are hints. Hosts that do not implement DHCPv6 ignore them, and a host can still configure itself with SLAAC if the A flag is 1.
The following Python function encodes the table:
def config_mode(m: bool, o: bool, autonomous: bool) -> str:
if m and not autonomous:
return "DHCPv6 address only"
if m:
return "SLAAC address plus DHCPv6 address"
if o:
return "SLAAC address, DHCPv6 for other options"
return "SLAAC only" if autonomous else "no address source"
print(config_mode(False, True, True)) # SLAAC address, DHCPv6 for other options
print(config_mode(True, False, False)) # DHCPv6 address onlyThe message exchange
DHCPv6 clients use UDP port 546 and servers and relay agents use UDP port 547. The client sends from its link-local address, so it needs no global address to start. It sends first messages to the multicast address ff02::1:2, which all servers and relays on the link listen to.
The stateful exchange has four messages:
- Solicit: the client looks for servers.
- Advertise: each willing server offers a configuration.
- Request: the client picks one server and asks for its offer.
- Reply: the server confirms the lease and the options.
Two shortcuts exist. With Rapid Commit, the client's Solicit asks for an immediate answer, and the server replies directly with a Reply. That makes a two-message exchange. Stateless clients use Information-Request and get a Reply containing only options. No lease is created.
Other messages manage the lease. Renew goes to the original server at time T1. Rebind goes to any server at T2 if Renew failed. Release gives an address back. Decline tells the server the address is already in use. Confirm checks whether the client's addresses are still valid after it moves to a new link.
Lifetimes
Each leased address has a preferred lifetime and a valid lifetime. After the preferred lifetime ends, the address is deprecated: existing connections may continue, but new ones should use a different address. After the valid lifetime ends, the address is removed. T1 and T2 are the Renew and Rebind timers, normally set to 50% and 80% of the preferred lifetime.
Identifying clients: DUID and IAID
DHCPv4 usually identifies a client by its MAC address. DHCPv6 uses a DUID (DHCP Unique Identifier), which is meant to stay the same for the whole device, even when interfaces change. Each interface's lease sits in an IAID (Identity Association Identifier) under that DUID.
Common DUID types are:
- DUID-LLT: link-layer address plus a timestamp.
- DUID-EN: an enterprise number plus a vendor-assigned ID.
- DUID-LL: link-layer address only.
- DUID-UUID: a UUID.
The next snippet builds a DUID-LL for an Ethernet card. Type 3 is DUID-LL and hardware type 1 is Ethernet:
def duid_ll(mac: str) -> str:
raw = bytes.fromhex(mac.replace(":", ""))
return (b"\x00\x03\x00\x01" + raw).hex(":")
print(duid_ll("00:1a:2b:3c:4d:5e")) # 00:03:00:01:00:1a:2b:3c:4d:5eBecause the DUID is not tied to a MAC address in the packet, reservations on the server must be keyed on the DUID. A common mistake is writing a reservation by MAC address and wondering why the host never matches.
Running a server
Many small networks use dnsmasq for both RAs and DHCPv6. This configuration hands out addresses from a pool and advertises a DNS server. Both enable-ra and the dhcp-range line matter: the first sends RAs with the M flag, and the second defines the pool.
enable-ra
dhcp-range=2001:db8:1::100,2001:db8:1::1ff,64,12h
dhcp-option=option6:dns-server,[2001:db8:1::53]Larger sites commonly use ISC Kea. On a Linux client, you can watch the exchange with tcpdump and see the result with ip:
sudo tcpdump -i eth0 -n "udp port 546 or udp port 547"
ip -6 addr show dev eth0A DHCPv6 address normally shows as a /128 with dynamic and finite valid_lft and preferred_lft. A SLAAC address shows the prefix length from the RA, normally /64.
Common pitfalls
- No default route. The server cannot provide one. If the router sends no RA, the client has an address but no gateway.
- Android. Android does not support stateful DHCPv6 address assignment. A network that sets M=1 and A=0 leaves those devices with no global address.
- Duplicate coverage. With M=1 and A=1, a host holds both a SLAAC and a DHCPv6 address. Source address selection picks between them, and access logs may show either one.
- Tracking by address. Since DHCPv6 leases tie to a DUID, an address assigned to a laptop stays the same on a network. This is useful for audit and a weaker privacy position than rotating SLAAC temporary addresses.
- Relays. On a routed network, DHCPv6 messages do not cross routers. A relay agent on each subnet must forward them to the server. The relay adds the client's link information so the server can choose the right pool.
- Firewalls. Allow UDP 546 and 547 on the local link, and ICMPv6 so RAs and Neighbor Discovery still work.
When to use which
| Need | Use |
|---|---|
| Hosts only need an address and a gateway | SLAAC |
| Hosts need DNS or NTP, and you accept SLAAC addressing | SLAAC plus stateless DHCPv6, or RDNSS in the RA |
| You must know which device holds which address, or keep logs per lease | Stateful DHCPv6 |
| Fixed addresses for servers or printers | Static configuration or DHCPv6 reservations |
| A router needs a prefix from the upstream network | DHCPv6 prefix delegation |
| Android phones are on the network | SLAAC, with M=0 or A=1 |
Many networks combine them: SLAAC for ordinary clients, DHCPv6 reservations for servers, and prefix delegation at the edge.
Exercise
A host receives an RA with M=1 and the prefix's A flag set to 0. It gets a DHCPv6 reply with an address. What prefix length will the address have in the DHCPv6 lease, and where does the host learn the default gateway?
Show answer
The DHCPv6 lease carries only the address, normally treated as a /128. The on-link prefix length comes from the Prefix Information option in the RA. The default gateway comes from the router's RA, because DHCPv6 has no gateway option.
Exercise
A server reservation is written with the client's MAC address, but the host keeps getting a pool address instead. What is the likely cause and fix?
Show answer
DHCPv6 identifies clients by DUID, not by MAC address. The reservation must use the client's DUID (and sometimes the IAID), which can be read from the client's DHCP state or from a captured Solicit.