Sub topic 7
Link-local addresses
This chapter assumes you know IPv6 notation and compression, prefix length, and the address types from the earlier chapters. A basic idea of how a switch and a router differ is also assumed.
What a link-local address is
A link-local address is valid only on one link. A link is a single Layer 2 segment, such as one Ethernet switch network or one Wi-Fi network. Link-local addresses use the prefix fe80::/10. In practice, nearly every address you see is in fe80::/64: 10 bits of prefix, 54 zero bits, then a 64-bit interface identifier.
Every IPv6-enabled interface configures one automatically, even when no router or DHCP server exists. That makes link-local addresses the base layer for the rest of IPv6. Neighbor Discovery and Router Advertisements both run over them. A host's default gateway is usually the router's link-local address.
Why routers never forward them
A router must not forward packets whose source or destination is link-local. The packet reaches neighbors on the same link and goes no further.
Because of this, the same link-local address can exist on different links without conflict. A router also has a different link-local address on each interface, or even the same one. The address alone does not say which link it belongs to.
Building one from a MAC address
The older modified EUI-64 method forms the interface identifier from the MAC address. It inserts ff:fe in the middle and flips the universal/local bit, which is bit 0x02 of the first byte.
import ipaddress
def eui64_link_local(mac):
b = bytearray(int(x, 16) for x in mac.split(":"))
b[0] ^= 0x02 # flip the universal/local bit
iid = bytes(b[:3]) + b"\xff\xfe" + bytes(b[3:])
return ipaddress.IPv6Address(b"\xfe\x80" + bytes(6) + iid)
addr = eui64_link_local("00:1a:2b:3c:4d:5e")
print(addr) # fe80::21a:2bff:fe3c:4d5e
print(addr.is_link_local) # TrueMany systems no longer derive the identifier from the MAC address. They use a stable random value instead, so you cannot always predict the address this way.
The zone ID
Since fe80::1 can exist on every link, a host with several interfaces cannot tell which one you mean. You add a zone ID after a %. On Linux it is the interface name. On Windows it is the interface number.
ip -6 addr show dev eth0
ping -6 -c 3 fe80::1%eth0The zone ID is a local label. It is not part of the address and never travels in a packet.
Common errors
- "Invalid argument" or "Network is unreachable" when pinging
fe80::...: you left out%interface. - Pinging a link-local address across a router: it fails by design. Use a global or unique local address.
- Using a link-local address in DNS or configuration files for remote use: it only works from hosts on the same link, and only with the right zone ID.
- Assuming the address is gone when no router exists: the link-local address stays, so hosts on the same switch can still talk.
Exercise
A host has two interfaces, eth0 and wlan0, and a neighbor has the address fe80::1. Why does ping -6 fe80::1 fail on this host, and how do you fix it?
Show answer
Both links could contain a neighbor named fe80::1, so the host cannot choose an outgoing interface. Add the zone ID, for example ping -6 fe80::1%eth0, to name the interface.