I used macvlan to connect container to network. Can the container connect to separate VLAN than host interface?

I have set up two LXD containers. I used macvlan to give each of these containers a separate virtual mac address. Originally, the containers and the host computer were all on the same subnet.

Now I am thinking that I would like to have the LXD containers on a separate VLAN than the main computer that these containers live in. Is this possible? It seems weird that it would be since the virtual adapters connect via a bridge with the physical adapter in the host computer.

Thanks!

Yes, you can use the vlan property on a macvlan NIC to specifiy what VLAN to use on the parent interface.

Thank you for the suggestion. I tried doing that, but it doesn’t seem to work. In this setup, does the host have to be configured to be on a VLAN?

At the moment, I have my host interface enp39s0 on the 192.168.0.1 subnet. This is not a VLAN. I then have the two LXD containers. I configured two separate profiles: macvlan (for the container that will be on the same subnet as the host) and macvlan-vnet10 (for the container that I want to be on the vlan 10).

The first macvlan profile is

config: {}
description: ""
devices:
  eth0:
    nictype: macvlan
    parent: enp39s0
    type: nic
name: macvlan
used_by:
- /1.0/instances/container1

The second profile, macvlan-10 is

config: {}
description: ""
devices:
  eth0:
    nictype: macvlan
    parent: enp39s0
    type: nic
    vlan: "10"
name: macvlan-vlan10
used_by:
- /1.0/instances/container2

The problem is that the second container doesn’t seem to get an ip address. The command ip addr show gives

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN     group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    9: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
        link/ether 00:[...hidden...]:4e brd ff:ff:ff:ff:ff:ff link-netnsid 0
        inet6 f[...hidden...]4e/64 scope link 
           valid_lft forever preferred_lft forever

Am I doing something wrong?