3

On a Ubuntu Xenial host I'm running LXD 2.12 from the xenial-backports. While it's easy to change a containers ipv4 address to a static address from outside the container I cannot change its ipv6 address. What is the right way to do this?

I configured lxd with an lxdbr0 bridge with IPv4 and IPv6. The related part in the config looks like this:

ipv4.address: 10.122.45.1/24
ipv4.nat: "true"
ipv6.address: fd42:7146:f400:1::1/64
ipv6.nat: "true"

After I launched a container with Xenial (contxenial) its ifconfig for eth0 looked something like this:

peter@led:~$ lxc exec contxenial -- ifconfig eth0
eth0 Link encap:Ethernet  HWaddr 00:16:3e:bc:f5:8d
     inet addr:10.122.45.223  Bcast:10.122.45.255  Mask:255.255.255.0
     inet6 addr: fd42:7146:f400:1:216:3eff:febc:f58d/64 Scope:Global
     inet6 addr: fe80::216:3eff:febc:f58d/64 Scope:Link
     :

Now I wanted to change both, its ipv4 AND its ipv6 address to static ip adresses using the following commands:

peter@led:~$ lxc network attach lxdbr0 contxenial eth0
peter@led:~$ lxc config device set contxenial eth0 ipv4.address 10.122.45.71
peter@led:~$ lxc config device set contxenial eth0 ipv6.address fd42:7146:f400:1::71

Finally I restarted my container.

peter@led:~$ lxc restart contxenial

To my surprise the IPv4 address changed as expected, but the IPv6 address did not!

peter@led:~$ lxc exec contxenial -- ifconfig eth0
eth0 Link encap:Ethernet  HWaddr 00:16:3e:bc:f5:8d
     inet addr:10.122.45.71  Bcast:10.122.45.255  Mask:255.255.255.0
     inet6 addr: fd42:7146:f400:1:216:3eff:febc:f58d/64 Scope:Global
     inet6 addr: fe80::216:3eff:febc:f58d/64 Scope:Link
     :

However, dnsmasq.hosts contains both, the changed IPv4 address as well as the changed IPv6 address.

peter@led:~$ sudo cat /var/lib/lxd/networks/lxdbr0/dnsmasq.hosts
00:16:3e:bc:f5:8d,id:*,10.122.45.71,[fd42:7146:f400:1::71],contxenial

What is it, I'm doing wrong? What is the right way to currently achieve this (since LXC/LXD 2.3 or higher)?

1 Answer 1

3

From Stéphane Graber, the project leader of LXC/LXD, I've got the following answer to my issue:

Static IPv6 assignment can only work in stateful DHCP mode as otherwise SLAAC is used to assign the address.

You can enable stateful DHCP with:

lxc network set lxdbr0 ipv6.dhcp.stateful true

But note that no Linux distribution does DHCPv6 by default, so you'll also need to update your container's /etc/network/interfaces (or similar based on distribution) to actually do DHCPv6.

This was the missing part I could not find in any documentation. It also means that it is not possible to change IPv6 addresses from outside the container the same simple way it can be done with IPv4.

In my case I had to add the following line to /etc/network/interfaces.d/50-cloud-init.cfg inside the container.

iface eth0 inet6 dhcp

Without comments it must look something like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
iface eth0 inet6 dhcp

The file is called from /etc/network/interfaces. It might be different on other distributions.

Finally it should work after a restart of the container (at least it worked for me).

I hope this helps others as well.

1
  • 1
    As a quick note, more recent versions of Ubuntu rely on netplan to configure network stuff. For example, in 17.10 (artful) distro, you'll find /etc/netplan/01-network-manager-all.yaml, which if changed, will need to have the changes applied by running sudo netplan apply.
    – code_dredd
    Apr 19, 2018 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .