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

[email protected]:/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

[email protected]:~# lxc-start -n ubuntu
[email protected]:~# lxc-ls –fancy
centos STOPPED – – NO
ubuntu RUNNING – NO

[email protected]:~# ovs-vsctl show
Bridge “switch0”
Port “switch0”
Interface “switch0”
type: internal
Port “lxc0”
Interface “lxc0”
ovs_version: “2.0.2”
[email protected]:~#

Test the connectivity to the container

[email protected]:~# 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