LXC container networking not working
On a Debian server, I installed lxc, but when I create a container, it is missing IP address. When I did “lxc-attack VM_NAME”, and checked the network interface with “ip link” command, i can only see the loopback interface “lo”.
On Host machine, when I checked network interfaces, lxcbr0 was missing. To fix this, edit file
1 |
vi /etc/default/lxc |
Find
1 |
USE_LXC_BRIDGE="false" |
Replace with
1 |
USE_LXC_BRIDGE="true" |
Now restart lxc-net service
1 |
systemctl restart lxc-net |
At this point, you will see the network interface “lxcbr0”.
1 2 3 4 5 6 7 |
root@b24:~# brctl show bridge name bridge id STP enabled interfaces br-52702762660a 8000.024201845e4b no docker0 8000.0242ee9122d8 no lxcbr0 8000.00163e000000 no vethDED0EK lxdbr0 8000.00163e7d81a2 no root@b24:~# |
Next edit file
1 |
vi /etc/lxc/default.conf |
I had the following content in this file
root@b24:/etc/lxc# cat default.conf
lxc.net.0.type = empty
lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1
root@b24:/etc/lxc#
Find
1 |
lxc.net.0.type = empty |
Replace with
1 2 3 |
lxc.net.0.type = veth lxc.net.0.link = lxcbr0 lxc.net.0.flags = up |
After this is done, newly created LXC containers get IP addresses.
1 2 3 4 |
root@b24:~# lxc-ls -f NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED vm-1 RUNNING 0 - 10.0.3.128 - false root@b24:~# |
See LXC