IPv6 Static Addresses using Tokens

Default Kernel IPV6 address creation
In an IPV6 network, addresses are usually self-assigned (constructed) by the kernel using both PREFIX: information provided by a router and :SUFFIX information from hardware (default from the MAC address). The router mechanism for this functionality is called "Router Advertisement" (RA). A machine usually has multiple IPV6 addresses for global, link or network scope. Since the IPV6 Prefix can change, addresses can not be assigned as simply as on IPV4.

goals of this article
Assign a static IPV6 suffix to an interface without additional software while keeping full RA functionality from the router.

default dynamic adresses
Let's take a look at a simple example configuration with IPV6 addresses completely self-constructed with prefix information received by a router. Note that the IPV4 configuration is already static:

when the interface is started, the address configuration could like this:

Note that the Suffix part 9802:79ff:fe45:ced2 is constructed out of the MAC address.

Drawbacks on self-constructed addresses
There are two drawbacks of fully self-constructed addresses. They are
 * complicated to read
 * depending on the MAC address
 * not associated with their IPV4 counterpart

So what if you change the network card? Right, all IPV6 addresses change. What if your machines have both IPV4 and IPV6 addresses? Right, they are completely different, not associated and hard to read.

Static (tokenized) IPV6 addresses
Since the Prefix can (and on dialup usually will) change, you cannot simply static addresses for all scopes. An easy solution is called IPv6 Tokenized Interface Identifiers: You give the kernel a hint on the address suffix. All together this means: Prefixes may change, the suffix will always stay the same. When combined with a fixed ULA Prefix (Unique Local Address Prefix) announced from the router, the site local address (usually fd00:...) will always stay the same.

Unfortunately, IPV6 tokens are not supported by netifrc yet, which is gentoos default framework for configuring network when using OpenRC. Further more, tokens can not be configured using sysctl.

Tokens can only be set using the ip (or ifconfig) command.

Example: Let's say you want to assign the simple suffix ::35 to interface eth0, in order to match the IPV4 counterpart 192.168.0.35:

As soon as you restart the interface, the changes apply:

Notice the new ::35 suffix on all IPV6 addresses except fe80 (which can be ignored, it's just the interface itself). In this example, the Router additionally announces a fixed ULA Prefix (Unique Local Address Prefix) of fd00:a. The full "Global" (WAN side) address of this interface is now 2a02:810a:8240:a2c::35, while the LAN (network) scope is simply fd00:a::35.

fd00:a::35 can now also be registered in local DNS for example.

We now have functional, easy to read and manage IPV6 addresses while keeping full RA functionality from the router. This means that the kernel will instantly re-configure the IPV6 address when for example the Prefix changes.

Putting it together: On boot
Since netifrc does not support tokens yet out of the box, you can not add simply add a parameter to /etc/conf.d/net.

The simple workaround is to call an ip command before launching an interface. This can easily be achieved by implementing a hook function directly in /etc/conf.d/net: