What is VLAN trunk mode?
In today’s blog post we will dive into VLAN trunk mode in Hyper-V 2012 R2. The same will apply to Windows Server 2016 Hyper-V and later version.
As you know, If you want to assign virtual machine network traffic to different VLANs, a network adapter that supports VLANs must be installed in the Hyper-V host and assigned to the virtual switch. You can set the VLAN ID for the virtual machine in the settings of the VM. The VLAN ID that is set in the virtual switch is the VLAN ID that will be assigned to the virtual network adapter (vmNIC) assigned to the host Operating System as showing in the following figure:
VLAN ID settings for Virtual Machine. (Image: @CharbelNemnom)
Hyper-V Virtual Switch also provides support for VLAN trunk mode. Trunk mode provides network services for a Virtual Machine with the ability to see traffic from multiple VLANs, in other words the virtual switch port receives traffic from all VLANs that you configure in an allowed VLAN list. You can also configure a switch port that is connected to a VM, but is not bound to the underlying NIC for trunk mode.
Configuring VLAN trunk mode for a (vmNIC) is not supported from Hyper-V Manager console; only a single VLAN can be configured as shown above.
How to do it?
With PowerShell, of course!
Set-VMNetworkAdapterVlan –VMName Demo –Trunk –AllowedVlanIdList 100-150 –NativeVlanId 20
In this example, “Demo” VM can send or receive traffic on any VLAN in the allowed list (100-150), and If there is no VLAN specified in the packet, the packet is treated as if it is from VLAN 20.
Note from the field
The NativeVlanId should not be within the scope listed in the AllowedVlanIdList (100-150), in other words if you set the Native VLAN ID to 110 for example, the VLAN 110 will be non functional, the VM itself will not be able to transmit tagged or untagged packets in VLAN ID 110.
If you have a virtual machine that requires access to more networks than available virtual adapters, then you can enable VLAN trunk mode by using the Set-VMNetworkAdapterVlan cmdlet.
Enjoy your day!