Guide

Tag a VM with a VLAN

One switch can carry several VLANs. Each VM's card is set to one VLAN, and a firewall's card is set to carry them all.

5 minutesRun on the Hyper-V host
What improves

One virtual switch carries several separate networks.

Why it matters

Without tags, every VM on the switch can talk to every other VM.

How you do it

Set each VM's network card to its VLAN, and set the firewall's card to carry them all.

Every name, address and value in this guide is an example. Replace them with your own.

Put a VM on one VLAN

Hyper-V host
Set-VMNetworkAdapterVlan -VMName "CON-DC-01" -Access -VlanId 20
Get-VMNetworkAdapterVlan -VMName "CON-DC-01"

The VM sees an ordinary network. Hyper-V adds and removes the VLAN tag for it.

Let a firewall carry several VLANs

Hyper-V host
Get-VMNetworkAdapter -VMName "CON-FW-01" | Where-Object SwitchName -eq "CON-LAN" |
  Set-VMNetworkAdapterVlan -Trunk -AllowedVlanIdList "10,20,30,40,50" -NativeVlanId 0

The firewall then handles the tags itself. Create VLANs has the full steps for pfSense.

Put the host on a VLAN

Hyper-V host
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "CON-LAN" -Access -VlanId 10

Take a VM off its VLAN

Hyper-V host
Set-VMNetworkAdapterVlan -VMName "CON-DC-01" -Untagged

See every VM's VLAN

Hyper-V host
Get-VM | Get-VMNetworkAdapterVlan | Format-Table ParentAdapter, OperationMode, AccessVlanId, AllowedVlanIdList
Your progress is kept in this browser only.