By default, lxd containers get random ip from lxd-bridge system. If you want to assign static IPs (i.e with some logical or arithmetic order), good news: It is quite simple.
All we need to do is create a DNS configuration file and tell lxd to use it.
There is a configuration file lxd-bridge under /etc/default/ directory. It is created when you first run lxd init command. It is something like this:
# WARNING: This file is generated by a debconf template!
Look that LXD_CONFILE. It is empty by default. We are going to put our configuration file’s path here. Let’s say we have 3 containers:
Now create a file named dns.conf under /etc/default/ directory:
$ sudo nano /etc/default/dns.conf
Put these lines in it:
The syntax is dhcp-host=container_name,ip_address.
## Path to an extra dnsmasq configuration file
That’s it. To make our changes work, we need to restart
$ sudo service lxd-bridge restart
We may need to reboot each container to take their new ip address:
$ lxc exec web_server /bin/bash
Now each container will have static ip based on our dns.conf file even if you reboot the system.