Lesson 09 intermediate

IPv6

Why IPv6 exists and how it differs from IPv4: 128-bit addresses and how to shorten them, global, link-local, unique local and multicast addresses, the /64 rule and site prefixes, the simpler header, SLAAC, DHCPv6, Neighbor Discovery, and running dual stack.

IPv4 has about 4.3 billion addresses; there are more connected devices than that. IPv6 fixes the shortage for good with 128-bit addresses, about 3.4 × 10^38 of them, and cleans up several IPv4 design decisions along the way. More than 45% of Google’s users reach it over IPv6, mobile networks run largely on it, and every major cloud supports it. If you run anything on the internet, you will meet it.

IPv4 vs IPv6

TopicIPv4IPv6
Address size32 bits128 bits
NotationDotted decimal 192.0.2.10Hex groups 2001:db8::10
Header20 to 60 bytes, variableFixed 40 bytes plus optional extension headers
Header checksumYes, recomputed every hopNone (layer 2 and 4 already check)
FragmentationRouters or hostsSource host only
Address configurationManual or DHCPSLAAC, DHCPv6 or manual
Address resolutionARP (broadcast)Neighbor Discovery (multicast ICMPv6)
BroadcastYesNo, multicast instead
NATCommon, out of necessityNot needed; every device can have a global address

Writing IPv6 addresses

An address is eight groups of four hex digits:

2001:0db8:0000:0000:0000:ff00:0042:8329

Two rules shorten it:

  1. Drop leading zeros in each group: 0db8 becomes db8, 0042 becomes 42.
  2. Replace one run of consecutive all-zero groups with ::.
2001:db8::ff00:42:8329

:: may appear only once, otherwise you could not tell how many zeros each one hides. In URLs, put the address in brackets: http://[2001:db8::10]:8080/.

Address types

PrefixTypePurpose
2000::/3Global unicastPublic, routable addresses (like public IPv4)
fe80::/10Link-localEvery interface has one; valid only on that link
fc00::/7 (in practice fd00::/8)Unique local (ULA)Private addressing, like RFC 1918
ff00::/8MulticastOne to many; replaces broadcast
::1/128LoopbackThe host itself
::/128Unspecified“No address yet”
2001:db8::/32DocumentationExamples, like this course
64:ff9b::/96NAT64IPv4 addresses embedded for IPv6-only networks

An interface normally has several IPv6 addresses at once: a link-local, one or more global, and often temporary privacy addresses.

$ ip -6 addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP
    inet6 2001:db8:4a:10:8f2e:61c4:b7a2:93d1/64 scope global temporary dynamic
       valid_lft 86188sec preferred_lft 14188sec
    inet6 2001:db8:4a:10:3e2c:4aff:fe1b:9c10/64 scope global dynamic mngtmpaddr
       valid_lft 86188sec preferred_lft 14188sec
    inet6 fe80::3e2c:4aff:fe1b:9c10/64 scope link
       valid_lft forever preferred_lft forever

The temporary address changes regularly and is used for outgoing connections, so websites cannot track the device by its address.

The /64 rule and site planning

In IPv6 the split is nearly always the same: the first 64 bits are the network (prefix + subnet) and the last 64 bits are the interface ID. LANs are /64, full stop: SLAAC depends on it.

A typical allocation chain:

WhoGetsNumber of /64 subnets
Regional registry to ISP/324,294,967,296
ISP to business site/4865,536
ISP to home/56 (sometimes /60 or /48)256
One LAN or VLAN/641

With a /48 like 2001:db8:4a::/48, the fourth group is your subnet number: 2001:db8:4a:10::/64 for VLAN 10, 2001:db8:4a:20::/64 for VLAN 20. A nice habit is to match the subnet number to the VLAN ID so the plan reads itself.

The IPv6 header

A fixed 40-byte header with just eight fields:

FieldPurpose
Version6
Traffic classQoS (same role as DSCP/ECN)
Flow labelMarks packets of one flow for load balancers
Payload lengthSize after the header
Next headerWhat follows: 6 TCP, 17 UDP, 58 ICMPv6, or an extension header
Hop limitSame role as IPv4 TTL
Source and destination128 bits each

Options moved into optional extension headers, chained by the Next header field, so routers can process the common case quickly.

How hosts get addresses

  • SLAAC (stateless address autoconfiguration): the router sends Router Advertisements (RAs) with the /64 prefix. The host builds its own address from the prefix plus an interface ID (random or derived from the MAC), and uses the router’s link-local address as its default gateway.
  • DHCPv6: a server hands out addresses (stateful) or just extra settings such as DNS servers (stateless). Note: the default gateway always comes from RAs, never from DHCPv6.
  • DHCPv6 prefix delegation: your home router asks the ISP for a /56 and carves /64s out of it for each LAN.
  • Manual: for servers and routers.

Neighbor Discovery (NDP)

ICMPv6 does the jobs that ARP and ICMP router discovery did in IPv4:

MessagePurpose
Router Solicitation / AdvertisementFind routers and the prefix
Neighbor Solicitation / AdvertisementFind a neighbor’s MAC address; detect duplicate addresses
RedirectPoint a host to a better first hop
$ ip -6 neigh
fe80::1 dev enp3s0 lladdr 00:1a:2b:3c:4d:5e router REACHABLE
2001:db8:4a:10::25 dev enp3s0 lladdr 52:54:00:7a:11:02 STALE
$ ip -6 route show default
default via fe80::1 dev enp3s0 proto ra metric 100 expires 1781sec pref medium

Never block all ICMPv6. IPv6 cannot even resolve neighbors or find routers without it, and path MTU discovery depends on “packet too big” messages. Allow at least the NDP types and “packet too big” in every firewall.

Testing IPv6

$ ping -6 -c 2 one.one.one.one
64 bytes from one.one.one.one (2606:4700:4700::1111): icmp_seq=1 ttl=57 time=12.4 ms
$ curl -6 -s https://ifconfig.me ; echo
2001:db8:4a:10:8f2e:61c4:b7a2:93d1
$ dig +short AAAA example.com

AAAA records map names to IPv6 addresses, the same way A records do for IPv4.

Dual stack and transition

Most networks run dual stack: every host has both IPv4 and IPv6, and applications prefer IPv6 when a name has an AAAA record. Browsers use Happy Eyeballs: they try both and use whichever connects first, so a broken IPv6 path costs only a few hundred milliseconds.

Other transition tools:

  • NAT64 + DNS64: an IPv6-only network reaches IPv4-only sites through a translator. Many mobile networks work this way.
  • 464XLAT: adds a small translator on the device so IPv4-only apps still work on an IPv6-only network.
  • Tunnels (6in4, and historically 6to4 and Teredo): carry IPv6 inside IPv4 where the path has no IPv6.

Exercise

What is the correct short form of 2001:0db8:0000:0000:0001:0000:0000:0001?

  1. 2001:db8::1::1
  2. 2001:db8::1:0:0:1
  3. 2001:db8:0:0:1::1:0
  4. 2001:db8:1:1
Show answer

Answer: B. :: can replace only one run of zero groups. Replacing the first run gives 2001:db8::1:0:0:1 (replacing the second, 2001:db8:0:0:1::1, is also valid but not offered). Two :: would be ambiguous.

Exercise

A host has only an fe80:: address on its LAN interface. What does that tell you?

  1. It has a working global IPv6 address
  2. It is using DHCPv6 prefix delegation
  3. IPv6 is disabled on the host
  4. It has not received a Router Advertisement with a global prefix
Show answer

Answer: D. Every IPv6 interface gets a link-local address automatically. A global address needs a prefix from a router (SLAAC) or DHCPv6, so check that the router sends RAs.

Exercise

Your ISP gives your site a /56. How many /64 networks can you create?

  1. 8
  2. 64
  3. 256
  4. 65,536
Show answer

Answer: C. From /56 to /64 is 8 bits, and 2^8 = 256. A /48 would give 65,536.

Key takeaways

  • IPv6 addresses are 128 bits; drop leading zeros and use :: once.
  • Global (2000::/3), link-local (fe80::/10), unique local (fd00::/8) and multicast replace IPv4’s classes and broadcast.
  • LANs are /64; sites get /48 or /56.
  • SLAAC builds addresses from Router Advertisements; the gateway always comes from RAs.
  • NDP uses ICMPv6, so firewalls must allow it.

FAQ

Do I need NAT with IPv6?

No. There are enough addresses for every device to have a global one. Security comes from a stateful firewall that blocks unsolicited inbound connections, which is what NAT was doing by accident in IPv4.

Why is my IPv6 address changing every day?

That is a temporary privacy address (RFC 8981), rotated so sites cannot track your device over time. The stable address is still there for incoming connections.

Should I disable IPv6 if I do not use it?

Generally no. Modern systems expect it, some features break without it, and many of your users already reach you over IPv6. Learn it and firewall it properly instead.

Is IPv6 faster than IPv4?

Not by itself. It can be slightly faster when it avoids carrier-grade NAT boxes on the IPv4 path, which is common on mobile networks.

↑ ↓ navigate Enter open Esc close