Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Distributing IPv6 over libvirt guests

profile picture
Author
Tuxifan
Published
2023-03-13
Time to read
4 minutes reading time

About the author- A hobby C++ programmer who loves to mess with memory

Introduction

In this tutorial you will learn how to distribute part of your pool of IPv6 addresses to your libvirt guests using bridges. This way, they will all have their own public IPv6.

Prerequisites

First of all, you need a dedicated server with libvirt installed as well as a /64 IPv6 subnet. This comes with most dedicated servers anyway. I will assume that your machine runs something like Debian, but it should be applicable to most other distros too.

What should you know before we start:

  • Your IPv6 subnet address (in this tutorial we'll be using 2001:db8:5678 as an example)

Step 1 - Install required packages

The only package you will need besides your existing libvirt installation is the bridge-utils and the ifupdown package:

sudo apt install bridge-utils ifupdown

Step 2 - Create the bridge interface

The next step is to create the bridge interface using the packages we just installed:

sudo brctl addbr br0

Step 2.1 - Assign a subnet

Next, we will assign a /96 subnet to the bridge. This should be enough; it is very unlikely that your dedicated server can run enough VMs to run out of addresses here.

sudo ip addr add <your /64 subnet>:1:0:0:1/96 dev br0

Example:

sudo ip addr add 2001:db8:5678:1:0:0:1/96 dev br0

Step 2.2 - Set it up

Now we can set it up (or: "enable it")

ip link set br0 up

Step 3 - Add the interface to a VM

We will now attach this bridge to a VM. To do that, run

sudo virsh

And enter:

edit --domain <name of the VM>

Now add the following entry to the devices node:

<interface type='bridge'>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
</interface>

Please note that the address depends on the total number of devices attached to the guest.

The interface should be hot-plugged to your VM now, so it's not going to require a reboot.

Step 4 - Set up your VM

You now need to set up the new network interface with the following static configuration:

auto enp7s0
iface enp7s0 inet6 static
  address <your /64 subnet>:1::<machine suffix>
  netmask 96
  gateway <your /64 subnet>:1::1

Example:

auto enp7s0
iface enp7s0 inet6 static
  address 2001:db8:5678:1::dead
  netmask 96
  gateway 2001:db8:5678:1::1

To do this on a Linux guest, just append these lines to your /etc/network/interfaces file. On a Windows guest, you will have to fill it in the Windows Settings app.

Tip: on Ubuntu, you might have to use netplan instead

Step 4.1 - Activate the config

The final step is to activate the config by restarting the networking service:

sudo systemctl restart networking

Your networking should be back up after just a few seconds. It will not interrupt your SSH session.

Conclusion

You can now SSH into your machine using the static address you filled in! Now, you could make your bridge configuration persistent by adding it to your hosts /etc/network/interfaces file, and you could install a DHCP server to automatically assign addresses.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue

Discover our

Dedicated Servers

Configure your dream server. Top performance with an excellent connection at an unbeatable price!

Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more