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

vi /etc/default/lxc 

Find

USE_LXC_BRIDGE="false"

Replace with

USE_LXC_BRIDGE="true"

Now restart lxc-net service

systemctl restart lxc-net

At this point, you will see the network interface “lxcbr0”.

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

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

lxc.net.0.type = empty

Replace with

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.

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

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *