IPv6 Addressing, Datagrams, and Coexistence with IPv4
Why IPv6
An IPv4 address has only 32 bits, allowing at most about 4.3 billion addresses. With the rapid growth of the Internet, the pool of assignable IPv4 address blocks has long been exhausted. CIDR and NAT (Sections 4.3 and 4.5) greatly delayed exhaustion, but both are only stopgaps. IPv6 extends addresses to 128 bits:
That is enough to give every device on Earth a great many addresses.
Writing IPv6 Addresses
An IPv6 address is written as eight groups of 16 bits, each shown as four hexadecimal digits and separated by colons, for example:
2001:0db8:0000:0000:0000:ff00:0042:8329Because this is long, two abbreviation rules apply:
- Leading zeros in each group may be omitted:
2001:db8:0:0:0:ff00:42:8329. - One run of consecutive all-zero groups may be replaced by two colons, "::":
2001:db8::ff00:42:8329. "::" may appear only once in an address; otherwise nobody could tell how many groups each occurrence hides.
When an address contains several runs of zero groups, the recommended form compresses the longest run, the first one on a tie, and normally does not compress a single zero group. To expand, subtract the number of written groups from eight: the result is the number of zero groups that "::" stands for.
As with CIDR, IPv6 writes network prefixes as address/prefix-length. The most common subnet prefix is /64: the first 64 bits are the network prefix and the last 64 bits are the interface ID.
| Address or prefix | Type | Notes |
|---|---|---|
| ::/128 | Unspecified | Used by a host that has no address yet, like IPv4's 0.0.0.0 |
| ::1/128 | Loopback | Like IPv4's 127.0.0.1 |
| fe80::/10 | Link-local | Valid on one link only; routers do not forward it |
| fc00::/7 | Unique local | For use inside an organization, like IPv4 private addresses |
| ff00::/8 | Multicast | Sent to a group of interfaces |
| 2000::/3 | Global unicast | Routable on the Internet |
IPv6 has no broadcast addresses; functions that used broadcast use multicast instead.
Shorten an IPv6 address by hand
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
The IPv6 Datagram Format
The IPv6 header has a fixed length of 40 bytes:
| Field | Size | Purpose |
|---|---|---|
| Version | 4 bits | 6 for IPv6 |
| Traffic class | 8 bits | Similar to IPv4's type-of-service field |
| Flow label | 20 bits | Identifies datagrams belonging to the same "flow" so routers can treat them alike |
| Payload length | 16 bits | Number of bytes after the header |
| Next header | 8 bits | Which protocol receives the data, or which extension header follows; same role as IPv4's protocol field |
| Hop limit | 8 bits | Decremented by each router; discarded at 0; same role as IPv4's TTL |
| Source and destination addresses | 128 bits each | IPv6 addresses of the sender and receiver |
Compared with IPv4, IPv6 makes several important simplifications:
- No fragmentation at routers. A router that receives a datagram that is too large drops it and sends an ICMPv6 "Packet Too Big" message to the source; only the source host may fragment.
- No header checksum. The link and transport layers already detect errors, so routers no longer recompute a checksum at every hop.
- Options move into extension headers chained by the next-header field. The fixed-length header lets routers process datagrams faster.
Transitioning from IPv4 to IPv6
Billions of IPv4-only devices are on the Internet, and there is no way to switch every device to IPv6 on a single day, so the two protocols must coexist for a long time.
In the dual-stack approach, nodes implement both IPv4 and IPv6: they use IPv4 with IPv4 nodes and IPv6 with IPv6 nodes.
Tunneling connects IPv6 "islands" separated by IPv4 networks. The dual-stack router at the tunnel entrance places the entire IPv6 datagram in the data field of an IPv4 datagram whose destination is the tunnel exit and whose protocol field is 41. IPv4 routers along the way process only the outer IPv4 header and do not know an IPv6 datagram is inside. The tunnel exit removes the IPv4 header and forwards the original IPv6 datagram.
Carry IPv6 through an IPv4 tunnel
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Compress, expand, and classify IPv6 addresses
(a) Write the recommended compressed form and the address type of:
fe80:0000:0000:0000:0204:61ff:fe9d:f1562001:0db8:0000:0001:0000:0000:0000:0001
(b) Expand to the full eight four-digit groups:
ff02::1:22001:db8:a::1
(c) An organization receives a /48. How many /64 subnets can it create?
Expand and compress IPv6 addresses in Python
Without using ipaddress for the conversion itself, write expand(text) that returns the full eight-group form and compress(full) that returns the recommended short form (drop leading zeros, replace the first longest run of at least two zero groups with "::"). Test on 2001:db8::ff00:42:8329, fe80::204:61ff:fe9d:f156, ::1, and 2001:0db8:0000:0001:0000:0000:0000:0001, and use ipaddress only to check your answers.