Attach LXD container to VLAN


(Gabriele Baldoni) #1

Hi all,

I was trying to attach an LXD container to a VLAN, in order to do this I have create the VLAN interfaces over the physical one, then added this interface to a LinuxBridge and attached the container to the Linux Bridge.
I made up a script to do this thing

#!/usr/bin/env bash

sudo ip link add link $1 name $1.$2 type vlan id $2
sudo ip link add vnet$2 type bridge

sudo ip link set vnet$2 up
sudo ip link set $1.$2 up

sudo ip link set dev $1.$2 master vnet$2

lxc profile copy default vlan$2
lxc profile device set vlan$2 eth0 parent vnet$2

lxc launch images:alpine/edge testc -p vlan$2
sleep 3
lxc exec testc -- ifconfig eth0 $3

read -n 1 -s -r -p "Press any key to destroy..."

lxc stop testc
lxc delete testc
lxc profile delete vlan$2
sudo ip link del vnet$2
sudo ip link del $1.$2

The setup follows this figure

I’m unable from the second server to ping the container, worth to say that if I just use the VLAN without LXD (meaning the two servers using VID 2) they can reach each other.
Any suggestion?
Maybe I have to configure something in the profile?