Sub topic 8
Unique local addresses
This chapter assumes you know how link-local and global unicast addresses work, and that you can read prefix-length notation. You should also be comfortable converting between hexadecimal and binary.
What a unique local address is
A unique local address (ULA) is an IPv6 unicast address meant for use inside a site or between a few cooperating sites. It is not meant to be reachable from the public Internet. The block is fc00::/7, defined in RFC 4193. ULAs are the closest IPv6 equivalent of IPv4 private ranges such as 10.0.0.0/8, with two differences. They are designed to be globally unique, and they are not translated by NAT in normal use.
Link-local addresses (fe80::/10) only work on a single link. ULAs are routable across subnets, so they work across your internal network. Your border routers must keep them from leaking out.
Structure of a ULA
The first 7 bits are 1111110. The 8th bit is the L flag.
fc00::/8has L = 0. It was reserved for a centrally assigned scheme that was never defined. Do not use it.fd00::/8has L = 1. This is the locally assigned block. In practice every ULA you meet starts withfd.
After the fd come 40 bits called the Global ID. Then come a 16-bit subnet ID and a 64-bit interface identifier. The first 48 bits (fd plus Global ID) form your site prefix, a /48, just as in the subnet plan from the previous chapters.
Take fd12:3456:789a:5::10. The site prefix is fd12:3456:789a::/48. The subnet ID is 5, so the subnet is fd12:3456:789a:5::/64. The host part is ::10.
Why the Global ID must be random
The 40-bit Global ID gives about 1.1 trillion possible site prefixes. RFC 4193 asks you to pick it pseudo-randomly. Two organizations that choose randomly are very unlikely to collide.
That matters when networks merge, or when two sites are joined by a VPN. If both sites had picked fd00::/48 or some memorable pattern like fd00:1234:5678::/48, their addresses would overlap. You would then have the same renumbering problem that private IPv4 ranges cause when companies merge.
Python can generate a prefix for you:
import ipaddress
import secrets
def random_ula_prefix():
global_id = secrets.randbits(40)
value = (0xFD << 120) | (global_id << 80)
return ipaddress.IPv6Network((value, 48))
prefix = random_ula_prefix()
print(prefix) # for example: fd3c:91a7:5e02::/48
for subnet in list(prefix.subnets(new_prefix=64))[:3]:
print(subnet)The code builds the integer by placing 0xFD in the top 8 bits and the random 40 bits directly below it. The /48 network then holds 65,536 /64 subnets. Because the output is random, your addresses will differ from the comment.
Where ULAs are useful
- Stable internal addressing. Most ISPs hand out global prefixes that can change. Internal services such as printers, databases, and monitoring can use ULAs that never change when the ISP prefix does.
- Isolated networks. Labs, industrial networks, and test environments that never connect to the Internet can use ULAs without asking any registry for space.
- Private links between sites. Two offices joined by a VPN can address each other with ULAs. Unique Global IDs mean no overlap.
- Resilience. If the Internet uplink fails, hosts with ULAs can still reach each other.
Many hosts hold several addresses on one interface. A typical host has a link-local address, a global address, and a ULA. The operating system picks the source address for each connection.
| Property | Link-local `fe80::/10` | Unique local `fc00::/7` | Global unicast `2000::/3` |
|---|---|---|---|
| Reach | One link | Inside the site or private network | The whole Internet |
| Routed between subnets | No | Yes, internally | Yes |
| Changes with ISP | No | No | Usually yes |
| Needs registry or ISP | No | No | Yes |
| Present on every interface | Yes | No | No |
Keeping ULAs inside
A ULA is only "private" because of filtering. Nothing in the address itself stops a packet from being sent out. You must add rules at the border.
- Do not advertise
fc00::/7to your ISP in BGP, and drop it if it is received from outside. - Add a firewall rule that drops packets whose source or destination is in
fc00::/7at the Internet edge. - Do not publish ULA addresses in public DNS records. Use split-horizon DNS, so internal clients get AAAA records with ULAs and external clients do not.
Source address selection
When a host has both a ULA and a global address, it applies the rules from RFC 6724 to choose a source for each destination. Prefix matching and scope normally lead to sensible results. A ULA destination gets a ULA source. A global destination gets a global source.
There is one well-known surprise. The default policy table gives fc00::/7 a low precedence (3), while IPv4 addresses, which are treated as IPv4-mapped IPv6 addresses, get precedence 35. A name with both an IPv4 address and a ULA address may therefore connect over IPv4 on a dual-stack host. Operators who want clients to prefer the ULA must change the host's policy table, for example through a DHCP or group-policy setting.
NAT and ULAs
A host that has only a ULA cannot reach the Internet. Some deployments use IPv6-to-IPv6 Network Prefix Translation (NPTv6, RFC 6296) to map a ULA prefix to a global one. NPTv6 translates only the prefix and keeps the rest of the address. It is a stateless translation, which is simpler than IPv4 NAT, but it still breaks the end-to-end model. Prefer giving internal hosts a global address as well as a ULA. Let the ULA serve for internal traffic and the global address serve for Internet traffic.
Classifying a ULA in code
Python's is_private property is not a good test for ULAs. It returns True for several unrelated blocks, such as the documentation range 2001:db8::/32 and link-local addresses. Test membership in the ULA block directly instead:
import ipaddress
ULA = ipaddress.ip_network("fc00::/7")
for text in ["fd12:3456:789a::1", "fe80::1", "2001:db8::1", "fc00::1"]:
a = ipaddress.ip_address(text)
print(text, a in ULA, a.is_private)
# fd12:3456:789a::1 True True
# fe80::1 False True
# 2001:db8::1 False True
# fc00::1 True TrueThe last line shows that fc00::1 is inside fc00::/7 even though fc00::/8 should not be used. A strict check for locally assigned ULAs would test fd00::/8 instead.
On Linux, ip -6 addr show lists the ULAs on each interface. They appear as inet6 fd... with scope global, because the kernel does not distinguish ULAs from global addresses by scope.
Common errors
- Using
fd00::/48or another easy pattern. It defeats the uniqueness goal. Generate a random Global ID. - Using
fc00::/8. This half is reserved. Usefd00::/8. - Leaking ULAs. Missing border filters or public DNS records expose internal addresses.
- Expecting ULA-only hosts to reach the Internet. They need a global address or a translator.
- Expecting a ULA to be preferred over IPv4. The default policy table favors IPv4 over ULAs.
- Using
is_privateas a ULA test. Check membership infc00::/7.
Exercise
A site uses the address fd12:3456:789a:5::10. What is the site's /48 prefix, which /64 subnet is the host in, and why should the Global ID not have been something like 0000000000?
Show answer
The /48 prefix is fd12:3456:789a::/48 (the fd plus the 40-bit Global ID 12:3456:789a). The host is in fd12:3456:789a:5::/64, because the 16-bit subnet ID is 5. A Global ID of all zeros, or any easy-to-guess pattern, is likely to be chosen by other sites too. Two networks that later merge or connect over a VPN would then have overlapping prefixes and need renumbering. A random 40-bit Global ID makes such a collision very unlikely.