LXC bridged network in Virtualbox


Using a bridged network with LXC is useful when you need your containers to be on same LAN subnet as the rest of your devices.
Setting up bridged network is easy, this example is for Ubuntu using Netplan.

Create a netplan configuration file in /etc/netplan that looks like this:

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
  bridges:
    br0:
      dhcp4: no
      dhcp6: no
      addresses:
      - 192.168.1.10/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
        - 192.168.1.53
        search:
        - local.bits
      interfaces:
      - enp0s3
      parameters:
        # spanning tree protocol
        stp: true
        # time between device entering listening state and moving to forwarding state
        forward-delay: 4

Make sure to change the interface name to match your environment.
Apply the configuration change by running netplan apply

Assign the network bridge to a container:

lxc config device remove container1 eth0
lxc config device add container1 eth0 nic nictype=bridged parent=br0 name=eth0

Your container should now be on the same LAN subnet as host.
Configure a static IP or DHCP in the container and that should be that …

… except for one thing.

If your container host is a Virtualbox VM then you must enable promiscuous mode for your virtual network adapter.
Without that your container will be able to ping the host but no other device on the network.

Virtualbox network adapter

Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.