7

I've had limited success in having LXC instances acquire an IPv4 address. It has worked at creation, but if I reboot the host, all addresses are lost.

Host Ubuntu 21.10

Client version: 4.21

Server version: 4.21

Image Ubuntu 21.10

tgl@electra:~$ lxd version
4.21
tgl@electra:~$ lxc version
Client version: 4.21
Server version: 4.21
tgl@electra:~$ lxc list
+---------+---------+------+-----------------------------------------------+-----------+-----------+
|  NAME   |  STATE  | IPV4 |                     IPV6                      |   TYPE    | SNAPSHOTS |
+---------+---------+------+-----------------------------------------------+-----------+-----------+
| mariadb | RUNNING |      | fd42:594a:5292:77f3:216:3eff:fe3c:7abe (eth0) | CONTAINER | 0         |
+---------+---------+------+-----------------------------------------------+-----------+-----------+
| nginx1  | RUNNING |      | fd42:594a:5292:77f3:216:3eff:fe85:b910 (eth0) | CONTAINER | 0         |
+---------+---------+------+-----------------------------------------------+-----------+-----------+
| nginx2  | RUNNING |      | fd42:594a:5292:77f3:216:3eff:feb3:3103 (eth0) | CONTAINER | 0         |
+---------+---------+------+-----------------------------------------------+-----------+-----------+
| nginx3  | RUNNING |      | fd42:594a:5292:77f3:216:3eff:feaf:5288 (eth0) | CONTAINER | 0         |
+---------+---------+------+-----------------------------------------------+-----------+-----------+
| proxy   | RUNNING |      | fd42:594a:5292:77f3:216:3eff:fee7:5013 (eth0) | CONTAINER | 0         |
+---------+---------+------+-----------------------------------------------+-----------+-----------+
tgl@electra:~$ lxc network list
+--------+----------+---------+----------------+---------------------------+-------------+---------+
|  NAME  |   TYPE   | MANAGED |      IPV4      |           IPV6            | DESCRIPTION | USED BY |
+--------+----------+---------+----------------+---------------------------+-------------+---------+
| eth0   | physical | NO      |                |                           |             | 0       |
+--------+----------+---------+----------------+---------------------------+-------------+---------+
| lxdbr0 | bridge   | YES     | 10.88.102.1/24 | fd42:594a:5292:77f3::1/64 |             | 6       |
+--------+----------+---------+----------------+---------------------------+-------------+---------+
tgl@electra:~$ 
Terry G Lorber
  • 667
  • 2
  • 9
  • 14

2 Answers2

4

This worked for me:

sudo ufw allow in on lxdbr0
sudo ufw route allow in on lxdbr0
sudo ufw route allow out on lxdbr0

Via: https://discuss.linuxcontainers.org/t/lxd-bridge-doesnt-work-with-ipv4-and-ufw-with-nftables/10034/17

3

I've now found a couple resources:

https://discuss.linuxcontainers.org/t/containers-not-getting-ipv4/6668/37

https://discuss.linuxcontainers.org/t/lxd-bridge-doesnt-work-with-ipv4-and-ufw-with-nftables/10034/16

I am using lxd from snap on Ubuntu 21.10. After reading the second linked discussion, I disabled and removed ufw and re-install with snap.

sudo ufw disable
sudo apt remove ufw
sudo apt purge ufw
sudo snap install ufw
sudo ufw enable

Then sudo systemctl reload snap.lxd.daemon. The nginx process in each instance also needed to be restarted. Everything worked on reboot, too.

Alternately, you may have success with these two new ufw rules.

sudo ufw allow in on lxdbr0
sudo ufw route allow in on lxdbr0
Terry G Lorber
  • 667
  • 2
  • 9
  • 14