Sub topic 11
Planning subnets: /48 to /64
This chapter assumes you know CIDR prefix notation, hexadecimal, and how an IPv6 address splits into a prefix and an interface identifier.
The standard split
An IPv6 site usually receives a /48 prefix from its provider. Hosts on a normal LAN use a /64 subnet. That leaves 16 bits between the two, called the subnet ID. You choose the subnet ID yourself, and it identifies one subnet inside your site.
How many subnets?
The number of /64 subnets in a /48 is 2^(64 − 48) = 2^16 = 65,536. The subnet ID is the fourth group of the address. In 2001:db8:abcd:0010::/64, the subnet ID is 0010.
The ipaddress module can list the subnets in order:
import ipaddress
from itertools import islice
site = ipaddress.ip_network("2001:db8:abcd::/48")
print(2 ** (64 - site.prefixlen)) # 65536 possible /64 subnets
for subnet in islice(site.subnets(new_prefix=64), 3):
print(subnet)
# 2001:db8:abcd::/64
# 2001:db8:abcd:1::/64
# 2001:db8:abcd:2::/64Why always /64?
SLAAC (stateless address autoconfiguration) builds a host address from a 64-bit interface identifier. Subnets longer than /64 break it. So you do not conserve addresses by using smaller subnets, as you might in IPv4. Even a point-to-point link or a single-device VLAN normally gets its own /64.
Writing a plan
Choose subnet IDs that are easy to read and leave room to grow. One common method is to make the subnet ID match something you already number, such as the VLAN ID. Another is to group by function, for example 0000 to 00ff for infrastructure and 0100 to 01ff for user networks.
This script turns a plan into prefixes:
import ipaddress
site = ipaddress.ip_network("2001:db8:abcd::/48")
plan = {"servers": 0x0, "staff": 0x1, "guest": 0x10}
for name, subnet_id in plan.items():
base = int(site.network_address) + (subnet_id << 64)
print(name, ipaddress.ip_network((base, 64)))
# servers 2001:db8:abcd::/64
# staff 2001:db8:abcd:1::/64
# guest 2001:db8:abcd:10::/64The shift by 64 places the subnet ID just above the 64-bit interface identifier.
Common errors
- Reading the subnet ID as decimal.
2001:db8:abcd:10::/64is subnet 16, not 10. - Using a /64 only where hosts exist, and a longer prefix such as /126 on router links. Longer prefixes work for router-to-router links, but some features assume /64, so many sites use /64 everywhere.
- Handing out the whole /48 sequentially. Leave gaps so you can summarize several subnets as one route later.
Exercise
A site has the prefix 2001:db8:1200::/48. What is the /64 prefix for subnet ID 0x2a, and how many /64 subnets does the site have in total?
Show answer
The prefix is 2001:db8:1200:2a::/64. The site has 2^16 = 65,536 /64 subnets.