Lxc internal ip changes in reboot?

In lxd, containers have the same ip in each host reboot?

For the most part, yes.

The IP is calculated by dnsmasq based on the mac address. However, there is a tiny chance of collision resulting in two different MAC addresses hashing to the same IP address. In the unlikely event that you stop a container, launch a new one that collided, then started the original, the IP would change.

If you want to guarantee that the IP never changes you can set the IP statically, you can use the following:

  lxc network attach lxdbr0 <container> eth0 eth0
  lxc config device set <container> eth0 ipv4.address

This creates a device attached to the container with the static entries still assigned via DHCP. You can think of it as a ‘reserved address’ and see the configuration in /var/lib/lxd/networks/lxdbr0/dnsmasq.hosts/.

1 Like