Adding VLAN tags to ports of an unmanaged openvswitch bridge


I would like to add automatically specific VLAN tags on some LXD containers which use an openvswitch bridge. The bridge is not managed by LXD, but for the time being it is not a heavy constraint. Is such thing possible?

Supposedly I could run something like:

ovs-vsctl set port vethP5V71N@if171 tag=200

or if I have access to the actual initialization:

ovs-vsctl add-port br0 vethP5V71N@if171 tag=200

Hi joko,

It appears there was no reply so here is what we do hth. First visit our github Orabuntu-LXC which is build on LXC and OpenvSwitch.

There you will see that we use the following entries in the config file of the lxc container as shown: = /etc/network/if-up.d/openvswitch/ora73c10-pub-ifup-sw1 = /etc/network/if-down.d/openvswitch/ora73c10-pub-ifdown-sw1 = ora73c10


root@oowul:/var/lib/lxc/ora73c10# cat /etc/network/if-up.d/openvswitch/ora73c10-pub-ifup-sw1
ovs-vsctl add-port ${ovsBr} $5
ovs-vsctl set port $5 tag=10
root@oowul:/var/lib/lxc/ora73c10# cat /etc/network/if-down.d/openvswitch/ora73c10-pub-ifdown-sw1
sudo ovs-vsctl del-port ${ovsBr} $5
function CheckPortExists
sudo ovs-vsctl show | grep “$5” | grep Port | sed ‘s/^[ \t]//;s/[ \t]$//’ | cut -f2 -d’ ’ | sed ‘s/"//g’
if [ “$PortExists” = “$5” ]
sudo ovs-vsctl del-port ${ovsBr} $5
sudo ip link del $5

These commands will put the vlan tag on the openvswitch port at runtime when the container comes up and will optionally with the user of give the veth pair a meaningful name other than the machine generated vethXyZwuV cyborg-type random name.

Note, as I recall this may not work on LXD and I had logged some tickets and notes that LXD does not seem to have a streamlined way to do VLAN tagging (it must be added after the interface is up, by some semi-manual or scripted add-on outside of LXD config I think).

Reference here:

Anyway, maybe this will help.