An Introduction to IPv6

27 Dec 2022

This post is meant to be a quick introduction to IPv6. This post will only cover what I found interesting about the protocol. A lot of important but boring information has been omitted. I recommend going through the RFCs in the references section to get a detailed view of the protocol.

It would be helpful to have some familiarity with some basic networking concepts, i.e., how does a packet travel from a source device in one network to a destination device in a different network, to help you understand this blog easily.

Reason for IPv6

The main reason for moving from IPv4 to IPv6 is Expanded Addressing Capabilities. IPv4 has a total of 32 bits, which means it can only support 2^32 or roughly 4 billion addresses. The rate at which we were producing devices which are connected to the internet means that we will run out of IPv4 addresses. IPv6 consists of 128 bits, which can support 2^128 or 340 trillion trillion trillion (not a typo) addresses.

IPv6 Textual Representation Conventions

  • 2001:db8:aaaa:0000:0000:dddd:0000:0001
  • 2001:db8:aaaa:0000:0000:dddd:0000:001
  • 2001:db8:aaaa:0000:0000:dddd:0000:01
  • 2001:db8:aaaa:0000:0000:dddd:0000:1
  • 2001:db8:aaaa:0000:0000:dddd:0:1
  • 2001:db8:aaaa:0:0:dddd::1
  • 2001:db8:aaaa::dddd:0:1
  • 2001:db8:AAAA::DDDD:0:1

All the above addresses are the same IP address, and all of them are correct ways to represent the address. I could have created more permutations of the same address, but I think you get my point. We need conventions to help us represent IPv6 addresses textually:

Everything below are just conventions, an IPv6 parsing tool should support all correct representations of an address.

Leading Zeroes Must Be Suppressed

Anytime there are leading zeroes in a 16 bit field, it must be suppressed. So, 2001:db8:aaaa:bbbb:cccc:dddd:0000:0001 will be written as 2001:db8:aaaa:bbbb:cccc:dddd::1

Using ::

:: represents one or more 16-bit group of zeroes. You are allowed tp use :: in only one place in the entire address.

  • Shorten as much as possible using “::”. The address 2001:db8:0:0:0:0:2:1 must be shortened to 2001:db8::2:1. Likewise, 2001:db8::0:1 is not acceptable, because the symbol “::” could have been used to produce a shorter representation 2001:db8::1
  • "::" should not be used to shorten just one 16-bit 0 field. The representation 2001:db8:0:1:1:1:1:1 is acceptable, but 2001:db8::1:1:1:1:1 is not acceptable.
  • "::" should be used to shorten the first sequence of 0s if there are more than 1 sequence of 0s of equal length. The acceptable representation of 2001:db8:0:0:1:0:0:1 is 2001:db8::1:0:0:1 and not 2001:db8:0:0:1::1.

Use Lowercase Letters

When using the letters a-f as a part of the address, it should always be lowercase.

Combining IP with Ports

When combining IPv6 address and port, use [IPv6 Address]:Port format. Ex: [2001:db8::1]:80

IPv6 Addressing Architecture

A node is a device capable of sending and receiving IPv6 packets. A link is a communication medium in which the nodes can communicate at the link layer (Ethernet, PPP link, X.25). An interface is the node’s attachement to the link.

All IPv6 addresses fall under one of three categories:

  • Unicast (Represents a single interface; packets are delivered to the referred interface)
  • Anycast (Represents a group of interfaces; packets are only delivered to the interface nearest to the source with that address)
  • Multicast (Represents a group of interfaces; packets are only delivered to all interfaces with that address)

They can be differentiated by the address ranges:

Address Type Binary Prefix IPv6 Notation
Unspecified 00…0 (128 bits) ::/128
Loopback 00…1 (128 bits) ::1/128
Multicast 11111111 ff00::/8
Link-Local Unicast 1111111010 fe80::/10
Global Unicast Everything Else

IPv6 addresses are assigned to interfaces, not nodes. All interfaces must have atleast one link-local unicast address assigned to it. A single interface may also have multiple IPv6 addresses of any type (unicast, anycast, and multicast) or scope.

Unicast Addresses

  • Unicast addresses are similar to CIDR IPv4 addresses, i.e., they contain prefixes of arbitrary length. In general, an IPv6 unicast address has 2 parts: a n bit prefix and (128-n) bit identifier.

IPv6 unicast address composition

  • The interface IDs are used to uniquely identify an interface. It must be unique within a subnet, which means, the same interface ID can be used for multiple interfaces in the same node, as long as the interfaces have a different subnet ID.
  • For all unicast addresses, except those that start with the binary value 000, Interface IDs are required to be 64 bits long and to be constructed in Modified EUI-64 format.

Global Unicast Address

  • This is a subset of unicast address which are structured the following way:

IPv6 global unicast format

  • A global routing prefix is a value assigned to a cluster of subnets/links.
  • For all global unicast addresses, except those that start with the binary value 000, Interface IDs are required to be 64 bits long (n+m =64).

IPv4-Mapped IPv6 Address

  • This is a type of IPv6 address which has an IPv4 address embedded into it.
  • This is for use in applications which support IPv6 only but run in a dual-stack node which has both IPv6 and IPv4 enabled. In that scenario, IPv4 addresses are translated into IPv6 addresses by using IPv4-Mapped IPv6 addresses. The flow would look like:

ipv6 only application flow

  • It is structured as:

IPv4 embedded IPv6 address structure

There are other types of unicast addresses such as loopback address, link-local address which are not listed here.

Anycast Addresses

  • Anycast addresses are assigned to more than one interface (typically in different nodes), with the property that a packet sent to an anycast address is sent to the “nearest” interface having that address.
  • The routing algorithm calculates the nearness.
  • These are assigned from the unicast address space, which means they’re syntactically inditinguishable from unicast addresses.
  • When you assign an anycast address to an interface, that node must be configured to know that it’s an anycast address.
  • One expected use case of anycast addresses is that, anycast address is assigned to all routers of an organisation.

Subnet-Router Anycast Address

  • This is an anycast adress, which all routers are required to support for the subnets to which they have interfaces.
  • It is intended to be used for when an application needs to communicate with any one of the set of routers that are connected to the subnet.
  • The structure is as follows:

    required anycast address format

Multicast Addresses

  • The final type of IP address is the multicast address, which is an identifier to a group of interfaces.
  • There are certain addresses which are pre-defined by the protocol itself. These are used to refer to all nodes and routers in different scopes.

A Node’s Required Addresses

The following addresses are the ones that a host is required to identify itself by:

  • The required link-local address for each interface
  • Any additional unicast and anycast addresses that have been configured for the node’s interfaces
  • The loopback address.
  • The all-nodes multicast addresses
  • The solicited-node multicast address for each of its unicast and anycast addresses.
  • Multicast addresses of all other groups to which the node belongs.