How to make LXC container have DHCP IP in dedicated VLAN?

Currently I have setup two networks, one is for local network, one is for services which need to expose to Internet directly (like Nextcloud, Minecraft server, Proxy). The two networks are in different VLAN (VLAN 20 / VLAN 30).

I want to use LXC to run some services using VLAN 30. I have tried the guide on Internet and successfully create LXC container. However, the guide use local network bridge, which is different from macvlan. The LXC with bridge can only get a private internal IP address.

The other guides are using old(?) LXC command. I cannot find related configuration files in my installation (using sudo snap install lxd). I try to edit the instances config using lxc config edit mylxc but none of the parameters relate to network.

@testcb00

Sorry for my late reply, I finally get it works.

The simply method is to install Open vSwitch. The installation method can be found using Google search.

After the installation, enable and start the openvswitch.service.

Then create a Open vSwitch bridge (e.g. ovs-br0) and add your desired host interface (e.g. ens192) to the switch port.

ovs-vsctl add-br ovs-br0
ovs-vsctl add-port ovs-br0 ens192

Create a new lxc network profile and edit it

lxc profile create vlan30
lxc profile show default
lxc profile edit vlan30

or just edit the default profile

lxc profile edit default

config: {}
description: "Open vSwitch ens192 VLAN30 Profile"
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: ovs-br0
    type: nic
    vlan: "30"
  root:
    path: /
    pool: default
    type: disk
name: vlan30
used_by: []

Remind to bring the Open vSwitch Bridge interface up, and set it to up ONBOOT.

Use specific profile to launch new LXC container

lxc launch imagename containername --profile profilename