QEMU/KVM IPv6 Support

Overview
You have rented a whole server in a data centre somewhere and are running a few Kernel Virtual Machines (KVMs). Your provider gives you a single IPv4 address and a IPv6 /64 subnet. Its a nusciance to use IPv4 with non stanadard ports on the KVMs and you are too parsimonious to invest in more IPv4 addresses, its a hobby server after all. You get a single IPv4 address and a whole IPv6 /64 subnet, since your provider cannot give you any less.

Lets put the KVMs onto IPv6 so that they have global scope IPv6 addresses.

This guide is written around the use of libvirtd

Prerequsites

 * A working Gentoo host with IPv6 Support
 * One or more Gentoo KVM Guests with IPv6 Support
 * A IPv6 /64 prefix, like 2001:db8:dead:beef::/64
 * IPv6 working on the host

IPv6 support means USE="ipv6" in make.conf, kernel IPv6 support and packages like iproute2 installed. Other than iproute2, this is the Gentoo default.

Getting Started
on the hosts and KVM.

Do check that it is built with USE=ipv6. If emerge shows that its a rebuild, press n.

The Host Setup
Your KVM setup will have created an interface called virbr0.

The settings for this are stored in etc/libvirt/qemu/networks/default. You might want to backup this file before you start.

Edit virbr0
Stop the network, so you can edit the settings file. Don't even think of using $EDITOR

Add the following three lines above the existing closing tag.

Use your own /64 and make up your own prefix extension.

 

virsh net-edit will syntax check your edit and complain loudly if you mess up. This adds an IPv6 address to virbr0.

If you want to use DHCP for IPv6 in your KVMs, you probably don't, you can add a range statement here too. The range must be part of the prefix being assigned to virbr0

   Restart the network

Check virbr0
Notice that the interface virbr0 has aquired a /96 from your /64. That's as many IP addresses as there is in the entire IPv4 address space.

It's a really good idea not to use adresses from 2001:db8:dead:beef:fe::/96 outside of virbr0

KVM Setup
2001:db8::/32 — This prefix is used in documentation