Present Location: News >> Blog >> Connecting LXC to VirtualBox

Blog

> Connecting LXC to VirtualBox
Posted by prox, from Seattle, on June 01, 2015 at 23:09 local (server) time

I've often been annoyed at the way LXC does bridging.  Here's a sample common configuration:

lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.hwaddr = 00:50:56:1a:ad:dc

This assumes lxcbr0 is a bridge (created by brcrl addbr lxcbr0).  The above configuration will create a pseudo-random interface name that is mapped to the LXC and add it to the bridge, resulting in the following:

(starfire:19:58)# brctl show
bridge name	bridge id		STP enabled	interfaces
lxcbr0		8000.fe3ffd02f7b8	no		vethXHEHXF

This works well most of the time but not if you want to directly connect an LXC to something that has native bridging capabilities like VirtualBox.  Sure, you could create a host-only interface with VirtualBox and add it to lxcbr0 but this is really unneeded (and probably slow, too).

A better way is to dispense with the Linux bridge itself and have VirtualBox bridge directly to the virtual Ethernet.  This doesn't work out of the box because the interface name is pseudo-random.  However, I was looking through the lxc.container.conf(5) man page the other day and found the lxc.network.veth.pair option.  This allows one to specify the virtual Ethernet interface's name that appears on the outside of the container!

Here's a better sample configuration:

lxc.network.type = veth
lxc.network.veth.pair = foobar0
lxc.network.hwaddr = 00:50:56:1a:ac:cc

This creates a foobar0 interface that connects to the LXC, which can be bridged to VirtualBox through its native method:

VBoxManage modifyvm testvm --nic1 bridged --nictype1 82543GC --bridgeadapter1 foobar0

Easy!

> Add Comment

New comments are currently disabled for this entry.