How to attach LXC container to OVS (OpenvSwitch)
5 March, 2021 by
How to attach LXC container to OVS (OpenvSwitch)
| No comments yet

By default lxc containers will be attached to the Linux bridge lxcbr0

Create a new LXC container

lxc-create -n ubuntu -t ubuntu

Check the bridge configuration

root@ubuntu:/var/lib/lxc/ubuntu# brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.000000000000 no
lxcbr0 8000.fe048f61bf3a no veth3SN4AY
virbr0 8000.000000000000 yes

veth3SN4AY is the interface which is connected to the lxc container we just created.

Lets change this to OpenvSwitch

Create an OVS switch and assign IP

ovs-vsctl add-br switch0
ip add add dev switch0

Edit the LXC network configuration container configuration

Here is the relevant network configuration

vi /var/lib/lxc/ubuntu/config
# Network configuration = veth = up = lxcbr0 # Disabled the default bridge connectivity = /etc/lxc/ifup # Interface up configuration = /etc/lxc/ifdown # Interface down configuration = lxc0 # Interface name on OVS = 00:16:3e:15:b3:62 =

Interface up and down scripts for the LXC containers

cat /etc/lxc/ifup
ovs-vsctl –may-exist add-br $BRIDGE
ovs-vsctl –if-exists del-port $BRIDGE $5
ovs-vsctl –may-exist add-port $BRIDGE $5

cat /etc/lxc/ifdown
ovs-vsctl –if-exists del-port ${ovsBr} $5

Now start the contaier and check

root@ubuntu:~# lxc-start -n ubuntu
root@ubuntu:~# lxc-ls –fancy
centos STOPPED – – NO
ubuntu RUNNING – NO

root@ubuntu:~# ovs-vsctl show
Bridge “switch0”
Port “switch0”
Interface “switch0”
type: internal
Port “lxc0”
Interface “lxc0”
ovs_version: “2.0.2”

Test the connectivity to the container

root@ubuntu:~# ping -c 1
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.453 ms

Sign in to leave a comment