Sub topic 16
Living alongside IPv4
This chapter assumes you can read compressed IPv6 addresses, know the difference between global unicast, link-local, and unique local ranges, and understand routing and default gateways. It covers how IPv6 and IPv4 work together while the Internet moves from one to the other.
Why coexistence is needed
IPv4 and IPv6 are not compatible on the wire. An IPv6-only host cannot send a packet directly to an IPv4-only server, because the two protocols use different header formats and different address spaces. The transition has therefore taken decades, and most networks run both protocols for a long time.
Three families of techniques handle this:
| Technique | Idea | Typical use |
|---|---|---|
| Dual stack | Run IPv4 and IPv6 side by side | Default choice for enterprise and home networks |
| Tunneling | Carry one protocol inside the other | Reaching IPv6 across an IPv4-only link, or the reverse |
| Translation | Convert packets between protocols | IPv6-only networks that still need IPv4 content |
Dual stack
In a dual-stack network, every host and router has both an IPv4 and an IPv6 address on the same interface. Each protocol keeps its own routing table, its own default gateway, and its own firewall rules. This is the simplest approach to understand and the one that causes the fewest surprises for applications.
The cost is that you run two networks. You need two addressing plans, two sets of firewall policies, and two sets of monitoring. A rule that blocks a service over IPv4 does nothing for IPv6, so a service you thought was closed may still be reachable.
Choosing between the two protocols
A dual-stack client asks DNS for both record types. An A record holds an IPv4 address and an AAAA record holds an IPv6 address. If both exist, the client must pick one.
Modern clients use an algorithm called Happy Eyeballs (RFC 8305). It sorts the candidate addresses, prefers IPv6, starts a connection attempt, and starts the IPv4 attempt after a short delay (a few hundred milliseconds) if the first one has not succeeded. The first connection to complete wins. This hides broken IPv6 paths from users, but it can also hide them from you. Slow or failing IPv6 may go unnoticed because IPv4 quietly takes over.
dig AAAA example.com +short
dig A example.com +short
curl -6 -s -o /dev/null -w "%{remote_ip}\n" https://example.com
curl -4 -s -o /dev/null -w "%{remote_ip}\n" https://example.comTesting each protocol separately with curl -4 and curl -6 is the reliable way to confirm that both paths work.
IPv4 addresses inside IPv6 notation
IPv6 reserves a few formats that embed an IPv4 address. You will meet them in logs and socket APIs.
- IPv4-mapped addresses use the prefix
::ffff:0:0/96, for example::ffff:192.0.2.128. A dual-stack server socket that listens on::often reports IPv4 clients this way. The address never travels on the wire in this form. It is only a notation inside the operating system. - IPv4-compatible addresses (
::192.0.2.1) are deprecated. Do not use them.
import ipaddress
mapped = ipaddress.ip_address("::ffff:192.0.2.128")
print(mapped.ipv4_mapped) # 192.0.2.128When you write allow lists or access-control code, normalize these addresses first. Otherwise 192.0.2.128 and ::ffff:192.0.2.128 can fail to match each other, which can let a client bypass a rule.
Tunneling
A tunnel wraps one protocol's packets inside the other's. The outer packet crosses the foreign network, and the far end removes the wrapper.
Manually configured tunnels
A 6in4 tunnel places an IPv6 packet inside an IPv4 packet using IP protocol number 41. You configure both endpoints by hand, and they are fixed. Tunnel broker services have long used this to give a site an IPv6 prefix over an IPv4-only connection. Because the endpoints are known, it is predictable and easy to filter.
Automatic tunnels
Automatic mechanisms embed the IPv4 address in the IPv6 address so that no configuration is needed:
- 6to4 uses
2002::/16. The next 32 bits are the site's public IPv4 address, so2002:c000:0204::/48belongs to192.0.2.4. - Teredo uses
2001::/32and tunnels IPv6 through IPv4 NAT devices using UDP.
Both are legacy. 6to4 was deprecated by RFC 7526 because it relied on relays that were often unreliable and hard to secure. Teredo is a last resort for hosts behind NAT. Treat any traffic from these ranges as unusual on a modern network.
import ipaddress
addr = ipaddress.ip_address("2002:c000:0204::1")
print(addr.sixtofour) # 192.0.2.4Tunnel gotchas
Encapsulation adds bytes to each packet. A 6in4 tunnel adds a 20-byte IPv4 header, so the usable MTU shrinks from 1500 to 1480. IPv6 routers never fragment packets in transit, so the sender must learn the smaller size through Path MTU Discovery, which relies on ICMPv6 "Packet Too Big" messages. If a firewall drops ICMPv6, large transfers hang while small ones work. Allow ICMPv6 Packet Too Big messages.
Translation
Translation is the approach used when a network is IPv6-only but its users still need IPv4 sites. It has two parts.
- DNS64 is a DNS resolver feature. When a client asks for an AAAA record and the name has only an A record, the resolver builds a synthetic AAAA answer by placing the IPv4 address inside a special IPv6 prefix.
- NAT64 is a gateway that receives packets for that prefix, extracts the IPv4 address, and sends the traffic out over IPv4 using its own IPv4 address.
The well-known prefix for synthesis is 64:ff9b::/96. The 32-bit IPv4 address fills the last four bytes. A network operator can also use a prefix from their own address space.
You can build the synthesized address yourself:
import ipaddress
v4 = ipaddress.IPv4Address("192.0.2.33")
prefix = ipaddress.IPv6Network("64:ff9b::/96")
synth = ipaddress.IPv6Address(int(prefix.network_address) | int(v4))
print(synth) # 64:ff9b::c000:221Limits of translation
DNS64 and NAT64 break in several known cases:
- A program that uses a literal IPv4 address (for example
192.0.2.33typed into a config file) never asks DNS, so no synthesis happens. It fails on an IPv6-only network. - DNSSEC validation can fail on synthesized answers, because the resolver changed the response.
- Protocols that carry IP addresses in their payload, such as some older VoIP and FTP modes, can break.
464XLAT addresses the literal-address case. A client-side translator (CLAT) on the device converts IPv4 packets into IPv6, and the network's NAT64 converts them back. Mobile operators use it widely, so apps that hard-code IPv4 still work on IPv6-only cellular networks.
Choosing an approach
Pick the simplest option that fits your constraints:
- If you control the whole network and can get both address families, use dual stack.
- If your provider offers only IPv4 but you need IPv6, use a 6in4 tunnel to a broker as a temporary measure.
- If you are building a large IPv6-only network, such as a mobile or data-center fabric, use NAT64 with DNS64, plus 464XLAT for clients.
- Avoid 6to4 and Teredo for new deployments.
Exercise
A DNS64 resolver uses the well-known prefix 64:ff9b::/96. A site has only an A record of 198.51.100.7. What AAAA address does the resolver synthesize, written in compressed form?
Show answer
Convert each IPv4 byte to hex: 198 is c6, 51 is 33, 100 is 64, and 7 is 07. Place them in the last 32 bits of the prefix: 64:ff9b::c633:6407.
Exercise
Users on a 6in4 tunnel can load small web pages, but large downloads stall. What is the most likely cause, and what should you check?
Show answer
The tunnel's encapsulation lowers the MTU (to 1480 for 6in4), and ICMPv6 Packet Too Big messages are probably being dropped by a firewall. Path MTU Discovery then cannot work, so full-size packets disappear. Allow ICMPv6 Packet Too Big messages, or lower the MTU or TCP MSS on the tunnel.