IPv6 Addresses and Subnets

There’s a basic problem with IPv4: It provides only 4.29 billion addresses, and that’s just not enough. Without subnetting, that’s fewer than one address for every human being. Eventually, every person will have at least one IP-capable device.

Although IPv4 addresses haven’t run out yet, they’re becoming an increasingly scarce resource. Overly generous allocations in the early days, along with large chunks of address space reservations for special purposes, have accelerated exhaustion. The world is slowly grinding toward IPv4’s replacement: IPv6.

Some parts of the world already use IPv6 extensively. Even if your network doesn’t use IPv6 today, one day you’ll need it—probably without warning. Prepare yourself now, or one day you’ll discover that you needed it the week before.

IPv6 Basics

Like IPv4, IPv6 is a network layer protocol. IPv4 uses 32-bit addresses, usually expressed as four groups of decimal numbers from 0 to 255 (for example, 192.0.2.13). IPv6 uses 128-bit addresses, expressed as six groups of four hexadecimal characters separated by colons (for example, 2001:db8:0:bad:c0de:cafe). A 128-bit address space gives enough IPv6 addresses for every atom in the Earth to have more than 10 IP addresses. TCP, UDP, ICMP, and other protocols run atop it. IPv6 has its own layer 2 protocol, Neighbor Discovery, which replaces protocols such as Ethernet’s ARP.

The good news is that you don’t need to relearn the basics of networking. Hosts still need an IP address and a default gateway, routers still use a routing table, and you can almost—almost—substitute an IPv6 address for an IPv4 address and watch everything work. A web server doesn’t care if it binds to port 80 on 192.0.2.13 or on 2001:db8:a12a:bad:c0de:café. The server just accepts requests sent to it and responds appropriately. That said, software does need to change slightly, because our web server must be able to log connections from both IPv4 and IPv6 addresses. These changes have wide-reaching repercussions, and we’ll be sorting out edge cases for the next decade. But, in general, once you understand the new rules for IPv6, all of your networking knowledge is applicable.

Understanding IPv6 Addresses

As noted, IPv6 addresses are 128 bits, expressed as six colon-delimited groups of four hexadecimal characters each. As with decimal IPv4 addresses, you don’t need to display leading zeros in each group. The address 2001:db8:0:bad:c0de:cafe could also be written as 2001:db8:0000:0bad:c0de:cafe, but just as we wouldn’t write 192.000.002.013, we strip out the leading zeros in an IPv6 address.[29]

IPv6 addresses often contain long strings of zeros. This had to do with subnetting, which I’ll describe later in this section. As of this writing, the IPv6 address of Sprint’s website is 2600:0:0:0:0:aaaa. When consecutive groups include only zeros, as in this address, they’re replaced with two colons (::). This IP address is usually displayed as 2600::aaaa. You can do this only once per address, however. You can’t, for example, have the address 2600::1::1, because it’s ambiguous. Does 2600::1::1 represent 2600:0:0:1:0:1 or does it represent 2600:0:1:0:0:1? I don’t know, and neither does your server.

You’ve probably seen a port number added to an IPv4 address, such as 192.0.2.13:80. Using a colon to glue a port number to an IPv6 address would be confusing. The IPv6 address 2001:db8::bad:c0de:cafe:80 isn’t ambiguous, but if you read it quickly, you might miss the double colon and think this is an IP address ending in 80. If you’re adding a port number to an IPv6 address, enclose the address in square brackets, as in [2001:db8::bad:c0de:cafe]:80.

Viewing IPv6 Addresses

Use ifconfig(8) to see all IPv6 addresses assigned on your machine. Here, I give ifconfig the name of my network card, fxp0.

$ ifconfig fxp0
…
       inet 192.0.2.13 netmask 0xfffffff0 broadcast 198.0.2.255
       inet6 fe80::bad:c0de:cafe%fxp0 prefixlen 64 scopeid 0x2
       inet6 2001:db8::bad:c0de:cafe prefixlen 64 autoconf pltime 604399 vltime 2591599
…

The lines starting with inet6 are my IPv6 addresses. This interface has been assigned two IPv6 addresses: fe80::bad:c0de:cafe%fxp0 and 2001:db8::bad:c0de:cafe. (Wait … where did that %fxp0 come from? You’ll find out in Link Local Addresses. For now, just nod and smile, and keep reading.)

IPv6 Subnets

Unlike IPv4, where you can subnet at any bit, IPv6 is usually subnetted at colon boundaries. Colons appear every 16 bits, so the natural IPv6 subnets are /16, /32, /48, and /64. Though IPv6 standards recommend using /64 as the smallest possible network, many carriers use /80, /96, and /112 networks for special purposes. (I’ve also seen people use subnets not divided at 16-bit boundaries. I won’t cover them, but don’t let your brain explode when you encounter a /51.) IPv6 subnets are always expressed as a slash, also known as a prefix length, so you won’t see a netmask of ffff:ffff:ffff:ffff::, as you might in IPv4.

ISPs are usually issued a /32 or a /48 subnet and are expected to issue end-user networks, such as the typical home network, a /64 network. If ISPs do issue /64 subnets to their users, an end-user network will provide 264 IP addresses, or 18,446,744,073,709,551,616 IP addresses. (This will suffice for any number of televisions, phones, refrigerators, water faucets, vacuums, and network-enabled tacos.)

When you subnet at 16-bit boundaries, each network has 65,536 subnets of the next smaller size. A /32 contains 65,536 /48 networks, and a /48 contains 65,536 /64 networks.

Special IPv6 Addresses

Like its predecessor, IPv6 reserves several blocks of addresses for special purposes. You don’t need to memorize all of these reserved addresses, but some will appear in daily use.

localhost

IPv6’s localhost address, ::1/128, works much like 127.0.0.1 in IPv4: It always refers to the local machine. In OpenBSD, ::1/128 is always assigned to the lo0 interface.

Addresses beginning with fe8x: (where x is variable) are local to their interface. Every link has such link local addresses that are valid only on a specific local network. Even if an IPv6 network has no router, the hosts on the local, directly attached network can find each other and communicate using these local addresses. These networks are always /64 subnets. You’ll see identical IPv6 subnets on other interfaces and on networks completely disconnected from your network. That’s okay. These addresses are local to the link. For example, here’s a link local address on an OpenBSD machine:

inet6 fe80::bad:c0de:cafe%fxp0 prefixlen 64 scopeid 0x2

The link local address of this interface is fe80::bad:code:cafe. The trailing %fxp0 indicates that this address is local to the interface fxp0 and isn’t usable on any other interface on the machine. If your machine has an interface fxp1, and a host on that network tries to reach the address fe80::bad:code:cafe, this machine will not respond. This particular address is valid only for the network attached to interface fxp0.

You might note that the link local address has a section in common with the public IPv6 address on this network. That’s because an autoconfigured IPv6 address is usually calculated from the interface’s physical address; it doesn’t matter whether that autoconfigured address is on a public address or a link local address.

Assigning IPv6 Addresses

IPv6 clients can usually use autoconfiguration through router discovery, anIPv6 protocol where routers announce their presence on the network and the legitimate addresses to clients. Unfortunately, IPv6 autoconfiguration does not support common Dynamic Host Configuration Protocol (DHCP) options, such as assigning a Domain Name Service (DNS) server, let alone the options used for diskless configuration. If you have configured a DNS server—even IPv4 servers accessible on a dual-stacked host—autoconfiguration works just fine. If you run an IPv6-only network, you must either set up an IPv6 DHCP server to provide DNS server information to clients or configure DNS servers manually.

Servers should not use IPv6 autoconfiguration. A server usually needs a static IP address, even in IPv6. Similarly, routers cannot use autoconfiguration. If a host can forward packets, it requires a static IPv6 address.

You can assign multiple IPv6 addresses to a single interface by using aliases, just as with IPv4.

In IPv6, a client on a /64 network can use autoconfiguration.

IPv6 autoconfiguration resembles a stripped-down DHCP service. The router broadcasts subnet and gateway information, and the hosts configure themselves to use it. Hosts on a network smaller than /64 must be manually configured.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.129.253