Sub topic 14
Autoconfiguration with SLAAC
This chapter assumes you know how a link-local address is formed, what a /64 prefix is, and the basics of Neighbor Discovery. Stateless address autoconfiguration (SLAAC) is the method that lets a host build its own global address without a server that tracks leases.
The working model
A router tells hosts which prefix is in use on the link. Each host then adds its own 64-bit interface identifier to that prefix. No server records which host has which address, which is why the method is called stateless.
The host goes through these steps:
- It forms a link-local address (
fe80::/64plus an interface identifier). - It runs duplicate address detection (DAD). It sends a Neighbor Solicitation for its own tentative address to the solicited-node multicast group. If no one answers, the address is unique.
- It sends a Router Solicitation to the all-routers group
ff02::2. - A router replies with a Router Advertisement (RA). Routers also send RAs periodically without being asked.
- The host reads the Prefix Information option, combines the prefix with its identifier, and runs DAD again on the result.
What the Router Advertisement carries
The Prefix Information option controls the behavior:
- The prefix and its length. SLAAC requires a /64, because the interface identifier is 64 bits.
- The on-link flag (L). When set, hosts treat addresses in that prefix as reachable directly on the link.
- The autonomous flag (A). When set, hosts may build addresses from the prefix with SLAAC.
- The preferred lifetime and valid lifetime. After the preferred lifetime ends, the address is deprecated. Existing connections keep working, but new ones use a different address. After the valid lifetime ends, the address is removed.
The RA header also has the M and O flags. M says to use DHCPv6 for addresses. O says to use DHCPv6 only for other settings, such as DNS servers. The next chapters cover DHCPv6.
Building the address
The sketch below combines a prefix with the identifier from the earlier EUI-64 example.
import ipaddress
prefix = ipaddress.ip_network("2001:db8:abcd:1::/64")
iid = int(ipaddress.IPv6Address("::21a:2bff:fe3c:4d5e"))
addr = ipaddress.IPv6Address(int(prefix.network_address) | iid)
print(addr) # 2001:db8:abcd:1:21a:2bff:fe3c:4d5eMost modern systems do not use an EUI-64 identifier for global addresses. They use a random temporary identifier for outgoing connections, and a stable opaque identifier for the long-lived address.
Common errors
- Prefix longer than /64. Hosts will not autoconfigure from it. The fix is to advertise a /64.
- A flag cleared. The host learns the prefix but builds no address from it.
- No RA arrives. The router may not have IPv6 routing or RA sending enabled. On Linux, check with
ip -6 addr showand look for addresses markeddynamic. - Rogue RAs. Any device on the link can send an RA, and hosts will trust it. A misconfigured laptop can hand out a bad prefix or default route. Switches can filter this with RA Guard.
Exercise
A router advertises the prefix 2001:db8:10:5::/64 with the A flag set. A host has the interface identifier 0211:22ff:fe33:4455. What global address does it form, and what happens to the address when its preferred lifetime expires?
Show answer
The host forms 2001:db8:10:5:211:22ff:fe33:4455 (the prefix followed by the identifier, with the leading zero dropped in compression). It runs DAD on the address before using it. When the preferred lifetime expires, the address becomes deprecated: existing connections continue, but new connections use another address. It is removed when the valid lifetime expires.