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 192.168.100.1/24 dev switch0
Edit the LXC network configuration container configuration
Here is the relevant network configuration
vi /var/lib/lxc/ubuntu/config
# Network configuration
lxc.network.type = veth
lxc.network.flags = up
#lxc.network.link = lxcbr0 # Disabled the default bridge connectivity
lxc.network.script.up = /etc/lxc/ifup # Interface up configuration
lxc.network.script.down = /etc/lxc/ifdown # Interface down configuration
lxc.network.veth.pair = lxc0 # Interface name on OVS
lxc.network.hwaddr = 00:16:3e:15:b3:62
lxc.network.ipv4 = 192.168.100.10
Interface up and down scripts for the LXC containers
cat /etc/lxc/ifup
#!/bin/bash
BRIDGE=”switch0″
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
#!/bin/bash
ovsBr=’switch0′
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
NAME STATE IPV4 IPV6 AUTOSTART
————————————————
centos STOPPED – – NO
ubuntu RUNNING 192.168.100.10 – NO
root@ubuntu:~# ovs-vsctl show
3bd99bd5-2e3b-41b8-8d84-66a75ebb97cc
Bridge “switch0”
Port “switch0”
Interface “switch0”
type: internal
Port “lxc0”
Interface “lxc0”
ovs_version: “2.0.2”
root@ubuntu:~#
Test the connectivity to the container
root@ubuntu:~# ping -c 1 192.168.100.10
PING 192.168.100.10 (192.168.100.10) 56(84) bytes of data.
64 bytes from 192.168.100.10: icmp_seq=1 ttl=64 time=0.453 ms
https://infologs.wordpress.com/2015/06/19/how-to-attach-lxc-container-to-ovs-openvswitch/