ta-ching chen

1 minute read

 Table of Contents

Prerequisites 

  • Ubuntu 14.04 LTS (Trusty Tahr)

Steps 

/var/lib/lxc/<container name>/config for newly created container looks like following

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.hwaddr = 00:16:3e:aa:cc:9c

Because LXC not supports OVS add-port, so we have to remove following line

lxc.network.link = lxcbr0

And add following lines

lxc.network.script.up = /etc/network/if-up.d/lxc-ifup
lxc.network.script.down = /etc/network/if-down.d/lxc-ifdown 
lxc.network.veth.pair = <ovs port name>

In the end, /var/lib/lxc/<container name>/config should look like the following

lxc.network.type = veth
lxc.network.flags = up
lxc.network.script.up = /etc/network/if-up.d/lxc-ifup
lxc.network.script.down = /etc/network/if-down.d/lxc-ifdown 
lxc.network.veth.pair = <ovs port name>
lxc.network.hwaddr = 00:16:3e:aa:cc:9c

Now, we have to create “lxc-ifup” and “lxc-ifdown” for adding/removing port on OVS when container is launch/shutdown.

Add /etc/network/if-up.d/lxc-ifup with following lines

#!/bin/bash
ovsBr='lxcbr'
ovs-vsctl --may-exist add-br ${ovsBr}
ovs-vsctl --may-exist add-port ${ovsBr} $5

Add /etc/network/if-down.d/lxc-ifdown with following lines

#!/bin/bash
ovsBr='lxcbr'
ovs-vsctl --if-exists del-port ${ovsBr} $5

Before launching LXC containerBefore launching LXC container

Reference 

  •   Category
  • LXC
comments powered by Disqus