Sub topic 5
Unicast, multicast, and anycast
Prerequisites
This chapter assumes you know how IPv6 addresses are written and compressed, and how a prefix length splits an address into a network part and an interface part. It also assumes you know the IPv4 terms unicast and broadcast. Here you will learn the three ways an IPv6 packet can be delivered and how to recognize each one from the address.
Three delivery models
Every IPv6 destination address belongs to one of three types. The type decides how many receivers get the packet.
| Type | Meaning | Receivers | IPv4 counterpart |
|---|---|---|---|
| Unicast | Identifies one interface | One | Unicast |
| Multicast | Identifies a group of interfaces | Every member of the group | Multicast, and some uses of broadcast |
| Anycast | One address shared by several interfaces | The nearest one | No standard equivalent |
IPv6 has no broadcast address. Functions that IPv4 handled by broadcasting to every host on a link, such as ARP, now use multicast groups. Only the hosts that need a message receive it, so other hosts are not interrupted.
Unicast
A unicast address identifies a single interface. A packet sent to it is delivered to that interface only. Most traffic you see is unicast, and several scopes exist.
- Global unicast (
2000::/3) addresses are routable on the Internet. - Link-local (
fe80::/10) addresses work only on the attached link. - Unique local (
fc00::/7) addresses are for private use inside a site, and routers do not forward them to the Internet. - Loopback (
::1) and unspecified (::) are special cases. Loopback means "this host". Unspecified means "no address yet" and appears as a source during startup.
An interface normally holds several unicast addresses at once. A typical host has a link-local address, one or more global addresses, and sometimes a unique local address. The host picks among them with source address selection rules, so it can choose a different source address for each destination.
Multicast
A multicast address starts with ff (the prefix ff00::/8). A packet sent to it is delivered to every interface that has joined that group. The address has a fixed layout:
- The first 8 bits are
ff. - The next 4 bits are flags. The flags value
0marks a permanently assigned (well-known) group, and1marks a transient group. - The next 4 bits are the scope. The scope limits how far routers forward the packet.
- The remaining 112 bits are the group ID.
In ff02::1, the flags are 0, the scope is 2 (link-local), and the group ID is 1.
| Scope value | Name | Reach |
|---|---|---|
| 1 | Interface-local | Same interface (loopback use) |
| 2 | Link-local | Same link; routers never forward it |
| 4 | Admin-local | Smallest area an administrator configures |
| 5 | Site-local | One site |
| 8 | Organization-local | Several sites of one organization |
| e | Global | The whole Internet |
The same group ID can appear in several scopes. ff02::2 means all routers on this link. ff05::2 means all routers at this site.
Well-known multicast addresses
| Address | Group |
|---|---|
| `ff02::1` | All nodes on the link |
| `ff02::2` | All routers on the link |
| `ff02::1:2` | All DHCPv6 relay agents and servers |
| `ff02::fb` | Multicast DNS |
| `ff02::1:ff00:0/104` | Solicited-node addresses |
Solicited-node multicast
Address resolution works by multicast. Before a host sends to a neighbor, it must learn the neighbor's link-layer (MAC) address. IPv4 asks everyone with a broadcast ARP request. IPv6 sends the request to the neighbor's solicited-node address instead.
This address is built by appending the low 24 bits of the unicast address to the prefix ff02::1:ff00:0/104. Each interface joins the group for every unicast address it has. Few hosts on a link share the same low 24 bits, so usually only the intended neighbor has to process the request. A later chapter covers Neighbor Discovery in detail.
Decoding multicast in Python
The ipaddress module reports whether an address is multicast. The flags and scope are bit fields, which you can extract yourself. The first group is ffFS, so the second byte holds the flags in its high nibble and the scope in its low nibble.
import ipaddress
SCOPES = {
1: "interface-local",
2: "link-local",
4: "admin-local",
5: "site-local",
8: "organization-local",
0xE: "global",
}
def describe_multicast(text):
addr = ipaddress.IPv6Address(text)
if not addr.is_multicast:
return f"{text} is not multicast"
second_byte = (int(addr) >> 112) & 0xFF
flags = second_byte >> 4
scope = second_byte & 0xF
name = SCOPES.get(scope, "unassigned or reserved")
return f"{text}: flags={flags}, scope={scope} ({name})"
def solicited_node(text):
low24 = int(ipaddress.IPv6Address(text)) & 0xFFFFFF
base = int(ipaddress.IPv6Address("ff02::1:ff00:0"))
return ipaddress.IPv6Address(base | low24)
print(describe_multicast("ff02::1")) # ff02::1: flags=0, scope=2 (link-local)
print(describe_multicast("ff05::2")) # ff05::2: flags=0, scope=5 (site-local)
print(describe_multicast("2001:db8::1")) # 2001:db8::1 is not multicast
print(solicited_node("2001:db8::1:2:3456")) # ff02::1:ff02:3456In the last line, the low 24 bits of 2001:db8::1:2:3456 are 02:3456. They are appended to the solicited-node prefix to give ff02::1:ff02:3456.
You can also test multicast on a real link. The %eth0 suffix names the interface, and you should replace it with your own. Link-local multicast needs this suffix because the same address is valid on every link.
ping -6 -c 3 ff02::1%eth0Every IPv6 host on the link that answers ICMP echo replies to this one request. You will see one reply line per host.
Anycast
An anycast address is assigned to more than one interface, usually on different machines. Routing delivers a packet sent to it to the nearest interface, where nearest is measured by the routing protocol's metric.
Anycast has no special address range. Anycast addresses are taken from the unicast space and look like any other unicast address. What makes an address anycast is that several nodes advertise it. Two points follow from that:
- You must configure nodes explicitly to treat an address as anycast. A host will not discover this by itself.
- The standard says an anycast address must not be used as the source address of a packet. Replies come from the server's own unicast address.
The standard defines one anycast address in every subnet, the subnet-router anycast address. It is the subnet prefix with an interface ID of all zeros. For the subnet 2001:db8:abcd:1::/64, it is 2001:db8:abcd:1::. Every router on that subnet must accept packets sent to it. A related range at the top of each subnet's interface ID space is reserved for other anycast addresses.
Anycast in practice
Anycast is used mostly on the Internet, not within a LAN. Operators announce the same prefix from several locations with BGP. Clients reach the closest location. DNS root servers and content delivery networks work this way, and they get lower latency and some resilience to a failed site.
The main caveat is that "nearest" can change while a connection is open if routing changes. A TCP session whose packets suddenly reach a different server will break. Anycast therefore suits short exchanges, such as a DNS query, better than long-lived sessions. Operators who anycast TCP services must either keep routing stable or make the servers share session state.
Common errors
- Looking for a broadcast address. There is none. Use
ff02::1to reach all nodes on a link. - Pinging a link-local multicast address without an interface. The command fails or picks a link you did not intend. Add
%interface. - Treating anycast as a different address format. An anycast address looks like unicast. Configuration and routing make it anycast.
- Confusing the scope with the flags. In
ff02::1the0is the flags and the2is the scope. Reading them the other way round gives the wrong scope. - Expecting routers to forward
ff02::traffic. Link-local scope never crosses a router.
Exercise
A packet is sent to ff05::2. What type of address is this, what are its flags and scope, and which hosts receive it?
Show answer
It is a multicast address, because it starts with ff. The second byte is 05, so the flags are 0 (a permanently assigned, well-known group) and the scope is 5 (site-local). The group ID 2 means "all routers". Every router at the site that belongs to the group receives the packet, and routers do not forward it beyond the site boundary.
Exercise
Why do two servers in different cities both answer to 2001:db8:53::1 without a conflict, and why is this unsuitable for a long-running TCP download?
Show answer
The address is an anycast address. Both servers advertise it, and routing delivers each client's packets to the nearest one. Anycast looks like a normal unicast address, but several nodes are configured with it. A routing change in the middle of a download could send later packets to the other server. That server has no record of the TCP connection, so the connection breaks.