15.7. Calculating IPv6 Addresses

Calculating IPv4 addresses was enough fun, and now you have these gigantic IPv6 addresses to manage. Is there a tool like ipcalc to help you make sure you get your addressing right?

Yes, there is—ipv6calc. It's easy to use, as the following examples show.

This command analyzes whatever address you give it, both IPv4 and IPv6:

	$ ipv6calc --showinfo -m FC00:0:0:1::
	No input type specified, try autodetection...found type: ipv6addr
	No output type specified, try autodetection...found type: ipv6addr
	IPV6=fc00:0000:0000:0001:0000:0000:0000:0000
	TYPE=unicast,unique-local-unicast
	SLA=0001
	IPV6_REGISTRY=reserved
	IID=0000:0000:0000:0000
	EUI64_SCOPE=local

This example compresses an IPv6 address:

	$ ipv6calc --addr_to_compressed fc00:0000:0000:0001:0000:0000:0000:0000
	fc00:0:0:1::

This example partly uncompresses an IPv6 address:

	$ ipv6calc --addr_to_uncompressed fc00:0:0:1::
	fc00:0:0:1:0:0:0:0

This example spells it out completely:

	$ ipv6calc --addr_to_fulluncompressed fc00:0:0:1::
	fc00:0000:0000:0001:0000:0000:0000:0000

ipv6calc will figure out your DNS PTR records for you, so you can copy-and-paste them into your BIND zone files:

	$ ipv6calc --out revnibbles.arpa fc00:0:0:1::
	No input type specified, try autodetection...found type: ipv6addr
	0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.0.0.0.0.0.0.0.0.c.f.ip6.arpa.

You can convert IPv6 prefixes to IPv4, and the reverse:

	$ ipv6calc -q --action conv6to4 --in ipv4 192.168.1.10 --out ipv6
	2002:c0a8:10a::
	$ ipv6calc -q --action conv6to4 --in ipv6 2002:c0a8:aeb:: --out ipv4
	192.168.10.235

Calculating subnets is easier in IPv6 because you only have a single field in the address to worry about, and even though there are several different address ranges (see the chapter Introduction for a table of address ranges and types), the structure of the addresses is the same for every one. The first 64 bits, or four quads, are always the network prefix and subnet. The last 64 bits are always the interface address.

You can test using IPv6 over the Internet by signing up with a 6to4 tunnel broker. These are service providers that provide special routing to carry IPv6 traffic over IPv4 networks. Your IPv4 address is converted to hexadecimal format, and embedded in your IPv6 tunnel prefix. 6to4 addresses always start with 2002:

	2002:nnnn:nnnn::1