LXC Networking – Instances Do Not Have IPv4 Addresses

lxcnetworking

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:~$ 

Best Answer

This worked for me:

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

Reboot the system to get the firewall rules enabled. Via: https://discuss.linuxcontainers.org/t/lxd-bridge-doesnt-work-with-ipv4-and-ufw-with-nftables/10034/17