Sub topic 14
Autoconfiguration with SLAAC
This chapter assumes you know the structure of an IPv6 address, prefix length notation, link-local addresses (fe80::/10), and multicast scopes. It also assumes you know that a /64 is the standard subnet size. Here you will see how a host builds a global address without a server keeping a list of leases.
What SLAAC does
Stateless address autoconfiguration (SLAAC) lets a host form its own IPv6 addresses. The router announces a /64 prefix. The host appends a 64-bit interface identifier to that prefix. No server records which host has which address, which is why the process is called stateless.
SLAAC is defined in RFC 4862. It depends on Neighbor Discovery messages, which travel inside ICMPv6. The router sends Router Advertisements (RAs), and the host can ask for one with a Router Solicitation (RS).
The sequence of events
A host brings up an interface in this order:
- It creates a link-local address from
fe80::/64plus an interface identifier. - It runs duplicate address detection (DAD) on that address.
- It sends a Router Solicitation to the all-routers group
ff02::2. - A router replies with a Router Advertisement, or the host receives one of the router's periodic RAs.
- For each prefix marked for autoconfiguration, the host combines the prefix with an interface identifier.
- It runs DAD on each new address, then starts using it.
What a Router Advertisement carries
The RA holds the information the host needs. The most important parts are:
- Prefix Information option. It gives the prefix, its length, two flags, and two lifetimes.
- Router lifetime. A nonzero value makes the sender a default gateway candidate. A value of 0 means the router is not a default gateway.
- M and O flags. These tell the host whether to use DHCPv6. The DHCPv6 chapter covers them.
- Optional extras. Examples are the link MTU and DNS servers (the RDNSS option, RFC 8106).
The two flags inside the Prefix Information option decide how the host treats the prefix:
| Flag | Name | Meaning when set |
|---|---|---|
| A | Autonomous address-configuration | The host may build an address from this prefix using SLAAC |
| L | On-link | Addresses in this prefix are reachable directly on this link, without going through the router |
The A flag and the L flag are independent. A prefix with L set and A clear is on-link, but hosts must get addresses some other way, such as DHCPv6. A prefix with A set and L clear is unusual but legal.
The prefix also has two lifetimes. The preferred lifetime says how long the address can be used for new connections. The valid lifetime says how long it stays assigned at all. After the preferred lifetime ends, the address is deprecated: existing connections continue, and new ones use another address. After the valid lifetime ends, the address is removed. A router that wants to renumber a network re-advertises the old prefix with short lifetimes and announces the new one.
Why the prefix must be /64
SLAAC builds a 128-bit address from the prefix and a 64-bit interface identifier. On Ethernet and Wi-Fi the prefix therefore has to be 64 bits long. A router that advertises a /80 or /96 with the A flag set will not produce working addresses on most hosts, because they ignore a prefix that is not 64 bits. This is the most common reason for subnet plans that break SLAAC.
Building an address in code
The following Python function builds a SLAAC address from a /64 and a MAC address using the modified EUI-64 method. It refuses any prefix that is not a /64.
import ipaddress
def eui64_iid(mac):
b = bytearray(int(x, 16) for x in mac.split(":"))
b[0] ^= 0x02 # flip the universal/local bit
return bytes(b[:3]) + b"\xff\xfe" + bytes(b[3:])
def slaac_address(prefix, mac):
net = ipaddress.IPv6Network(prefix)
if net.prefixlen != 64:
raise ValueError("SLAAC requires a /64 prefix")
return ipaddress.IPv6Address(net.network_address.packed[:8] + eui64_iid(mac))
print(slaac_address("2001:db8:abcd:1::/64", "00:1a:2b:3c:4d:5e"))
# 2001:db8:abcd:1:21a:2bff:fe3c:4d5eThe first byte 00 becomes 02 after the flip, and ff:fe goes in the middle. That gives the identifier 021a:2bff:fe3c:4d5e, which compresses to 21a:2bff:fe3c:4d5e.
Duplicate address detection
Before a host uses an address, it checks that no other host on the link already has it. It sends a Neighbor Solicitation for its own tentative address. The source is the unspecified address ::, and the destination is the solicited-node multicast address of the tentative address. If any host answers, the address is a duplicate and the host does not use it.
The solicited-node address is ff02::1:ff00:0/104 with the low 24 bits of the unicast address appended:
import ipaddress
def solicited_node(addr):
low24 = int(ipaddress.IPv6Address(addr)) & 0xFFFFFF
base = int(ipaddress.IPv6Address("ff02::1:ff00:0"))
return ipaddress.IPv6Address(base | low24)
print(solicited_node("2001:db8:abcd:1:21a:2bff:fe3c:4d5e"))
# ff02::1:ff3c:4d5eHosts that share the same last 24 bits share a solicited-node group. This keeps neighbor lookups from waking every host on the link.
Which interface identifier is used
The interface identifier does not have to come from the MAC address. A MAC-based identifier is the same on every network, so anyone who sees your address in different places can recognize the device. Operating systems use other choices:
- Stable opaque identifiers (RFC 7217). The host hashes the prefix, the interface name, and a secret key. The result is stable on one network and different on another.
- Temporary addresses (RFC 4941). The host generates random identifiers and replaces them regularly. It uses them for outgoing connections, which limits tracking.
- Manual or DHCPv6 identifiers. Servers often use these so that addresses stay predictable.
A typical modern host holds several addresses at once: a link-local address, a stable global address, and one or more temporary global addresses. Use the stable address for inbound services and DNS records, and expect outbound traffic to come from the temporary one.
Checking SLAAC on Linux
The ip command shows flags and lifetimes that identify how each address was formed.
ip -6 addr show scope global
ip -6 route show default
sysctl net.ipv6.conf.eth0.accept_raIn the first command's output, dynamic means the address came from an RA. mngtmpaddr marks the address that temporary addresses are derived from, and temporary marks the temporary ones themselves. The valid_lft and preferred_lft values count down from the advertised lifetimes. A default route with proto ra was learned from a Router Advertisement. Replace eth0 with your interface name.
Common errors
- No global address, only
fe80::. The host heard no RA, or the prefix had the A flag clear. Check that the router has RAs enabled on that interface, and that the host hasaccept_raturned on. - Prefix longer or shorter than /64. SLAAC ignores the prefix. Use a /64 for every SLAAC segment.
- Address stuck as tentative or marked
dadfailed. DAD found a duplicate, or the link drops multicast. Some Wi-Fi equipment filters the solicited-node group. - Host has an address but no route out. The RA's router lifetime was 0, so the sender is not a default router.
- No DNS servers. SLAAC alone does not provide DNS unless the RA includes the RDNSS option. Use that option or stateless DHCPv6.
- Forwarding enabled on a Linux host. Linux ignores RAs when it forwards packets unless
accept_rais set to 2.
Exercise
A router advertises the prefix 2001:db8:10:5::/64 with the A flag set, the L flag set, a valid lifetime of 7 days, and a preferred lifetime of 1 day. A host has the MAC address 52:54:00:12:34:56 and uses the modified EUI-64 method. What global address does it form, and what happens to the address after 1 day and after 7 days?
Show answer
Flip the universal/local bit of the first byte: 52 becomes 50. Insert ff:fe in the middle: 50:54:00:ff:fe:12:34:56, which is the identifier 5054:ff:fe12:3456 in compressed form. The address is 2001:db8:10:5:5054:ff:fe12:3456. After 1 day the address becomes deprecated, so existing connections continue but new connections prefer another address. After 7 days the address is removed unless a new RA refreshes the lifetimes. Before using it, the host runs DAD.
Exercise
A network engineer assigns the prefix 2001:db8:20::/96 to a Wi-Fi segment and sets the A flag. Hosts get only link-local addresses. Why, and how do you fix it?
Show answer
SLAAC needs a 64-bit prefix so that a 64-bit interface identifier completes the 128-bit address. Hosts ignore a /96 with the A flag set. The fix is to advertise a /64, for example 2001:db8:20:1::/64, from the site's larger allocation.