Networking Issues in LXC Container


I have a requirement to setup LXC containers in a OpenWRT Machine.

My System Details:
Laptop OS: Debian GNU/Linux bullseye/sid, 9.12 – Network is available. Everything works fine

VM OS: OpenWRT 19.07.2 – Network is available. Everything works fine

Container OS: OpenWRT 19.07 – Network is Unavailable. This is the issue

The VMs Configurations are as follows:

--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled

--- Control groups ---
Cgroups: enabled

Cgroup v1 mount points: 

Cgroup v2 mount points: 

Cgroup v1 systemd controller: /usr/bin/lxc-checkconfig: line 167: printf \033[1;31m: not found

Cgroup v1 freezer controller: /usr/bin/lxc-checkconfig: line 174: printf \033[1;31m: not found

Cgroup v1 clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled, loaded
Macvlan: enabled, loaded
Vlan: enabled, not loaded
Bridges: enabled, not loaded
Advanced netfilter: enabled, not loaded
CONFIG_NF_NAT_IPV4: enabled, loaded
FUSE (for use with lxcfs): missing

--- Checkpoint/Restore ---
checkpoint restore: missing
File capabilities: enabled

brctl show
bridge name	   bridge id		     STP enabled	   interfaces
br-mng		   7fff.0800272bc85f	 no		           eth0

cat /proc/net/arp
IP address       HW type     Flags       HW address            Mask     Device
10.0.XX.XX        0x1         0x2         52:54:00:12:35:02     *        eth1
192.168.XX.XX     0x1         0x2         0a:00:27:00:00:03     *        br-mng

The /etc/lxc/default.conf file in Virtual Machine has the following entries = veth = br-mng = up = 08:00:27:2b:c8:5f

The ifconfig -a output of the VM is:

br-mng    Link encap:Ethernet  HWaddr 08:00:27:2B:C8:5F  
                --- Some lines ---

eth0      Link encap:Ethernet  HWaddr 08:00:27:2B:C8:5F  
          		  --- Some lines ---

eth1      Link encap:Ethernet  HWaddr 08:00:27:79:CB:CF  
              --- Some lines ---

eth2      Link encap:Ethernet  HWaddr 08:00:27:4F:C7:A5  
             --- Some lines ---

lo        Link encap:Local Loopback  
           --- Some lines ---

vethXH0YJS Link encap:Ethernet  HWaddr FE:61:34:FE:61:12 
          --- Some lines ---

I have created a container inside the VM. The container starts fine and i am able to perform lxc-attach and other basic operations.

In VM, the entries of /srv/lxc/MyContainer/config are: = veth = br-mng = up = 08:00:27:2B:C8:5F

However the container doesn’t have network access.

When i try to run opkg update command inside MyContainer, it throws error message Failed to establish connection. ping also doesn’t work

The brctl show and /proc/net/arp commands give blank response inside container

Additional Info:

  1. I have set Promiscuous mode in Virtual Box as Allow All. Irrespective of the option that i choose in this dropdown, network is not available inside the conatiner
  2. When i execute the command lxc-ls -f, i see the IPv4 address as for a brief moment and then it disappears and it is shown as -

Could you please help me to resolve the network issues in my container.

Am i missing anything?

I dont think having this line = 08:00:27:2b:c8:5f in /etc/lxc/default.conf, and by extension, /srv/lxc/MyContainer/config is going to work, as that means:

A) That all of your containers will have the same MAC address (expect Ethernet conflicts).
B) The MAC address you’ve specified is the same MAC as the parent bridge interface.

Unless you want a specific MAC address ‘pattern’, then I would suggest removing that line from /etc/lxc/default.conf and changing the MAC address line in /srv/lxc/MyContainer/config to a different MAC address.

@tomp thanks for your response.

I removed the line from /etc/lxc/default.conf
Then i tried setting different mac addresses in /srv/lxc/MyContainer/config. Still same issue - Network unavailable.

I also tried by removing the line from /srv/lxc/MyContainer/config. Basically no hwaddr lines in any conf file. This also did not work.

lxc-net service is not available in my OpenWRT virtual machine. I think this is the reason for networking issues inside the container.

unable to install lxc-net package. I am getting error as package not found.

lxc-net is a script that comes with LXC itself usually, but maybe it wasn’t included in openwrt as openwrt itself is quite capable of creating bridges and running DHCP/DNS on them.

Thank you. I will rebuild the OpenWRT image and try again.

Finally, the issue is resolved.

The issue in case was Adapter-1 of the VM (in virtual box) was host only adapter. I had three adapters:
Adapter-1: Host Only
Adapter-2: NAT
Adapter-3: Bridged

Having only NAT and Bridged worked for me.

Other configurations are same as mentioned in my question.