Octet

A host has five IPv6 addresses. How does it decide which one to use as the source?

Show the answer

Say this first

RFC 6724 defines the rules. For the source: prefer the same address as the destination, then matching scope, avoid deprecated addresses, prefer the outgoing interface, prefer a matching label from the policy table, prefer temporary addresses, then the longest matching prefix. The same RFC also orders destinations when DNS returns several, which is why IPv6 is normally tried before IPv4 and why ULA loses to IPv4.

Go deeper

Source address rules, in order

  1. Prefer the same address as the destination.
  2. Prefer the appropriate scope (link-local for link-local destinations, global for global).
  3. Avoid deprecated addresses (preferred lifetime expired).
  4. Prefer home addresses (Mobile IPv6).
  5. Prefer addresses on the outgoing interface.
  6. Prefer a matching label in the policy table.
  7. Prefer temporary addresses.
  8. Use the longest matching prefix.

Default policy table

PrefixPrecedenceLabel
::1/128500
::/0401
::ffff:0:0/96 (IPv4)354
2002::/16 (6to4)302
2001::/32 (Teredo)55
fc00::/7 (ULA)313

Destination ordering

With several AAAA and A records, rules such as "prefer matching label" and "prefer higher precedence" put native IPv6 above IPv4, and IPv4 above Teredo, 6to4 and ULA. Happy Eyeballs then races the attempts so a broken path costs only a short delay.

Where to change it

  • Linux (glibc): /etc/gai.conf.
  • Windows: netsh interface ipv6 show prefixpolicies, and set prefixpolicy to change it.

Traps

  • Saying the host uses "its first address".
  • Forgetting that applications can bind to a specific source and bypass the rules.
How did you do?Book 4.2 IP Version 6