Virtual LAN domains isolate the network traffic of servers/computers from other computers. Hyper-V also provides...
the VLAN domain concept, where you can isolate VM traffic from other VMs connected to the same Hyper-V virtual switch. Although you can create a separate Hyper-V virtual switch and then connect only the VMs that require isolation, you can avoid the overhead of creating and managing another VM with the Hyper-V VLAN concept.
You can configure Hyper-V virtual switches in either Access mode or Trunk mode. It's important to note that you can only configure external and internal Hyper-V virtual switches in Trunk mode or Access mode.
You can use PowerShell cmdlets or Hyper-V Manager to query and assign VLAN IDs to the Hyper-V virtual switch. However, it's easier to use Hyper-V Manager because all you need to do is open the property page of a Hyper-V virtual switch, tick the Enable virtual LAN identification for management operating system option and then specify the VLAN ID in the VLAN ID box.
Once you've configured Hyper-V virtual switches in either Access mode or Trunk mode, the next step is to configure VMs to use a VLAN ID. To configure VMs with VLAN IDs, go to the property page of a VM, select the virtual network adapter -- which is connected to the Hyper-V virtual switch -- tick the Enable Virtual LAN Identification option and then specify the VLAN ID in the VLAN ID box.
You can assign a VLAN ID on the property page of a VM using Hyper-V Manager, but using the site-VMNetworkAdapterVLAN PowerShell cmdlet can help you configure VLAN IDs for multiple VMs. To configure VLAN IDs for a particular VM using PowerShell, execute the PowerShell command below:
Set-VMNetworkAdapterVLAN –VMName SQLVM –Access –VLANID 100
This command configures SQLVM to use VLAN ID 100 and tags the outbound traffic this VM sends with VLAN ID 100. The VMs configured with the same VLAN ID -- 100, in this case -- will be able to receive the traffic from SQLVM. Other VMs will just drop the traffic.
If you want to configure the VLAN ID for several VMs, create a text file that -- assuming VM names are mentioned in the C:\Temp\VMFile.txt file -- contains VM names and then use the PowerShell script below:
ForEach ($VMName in GC C:\Temp\VMFile.TXT)
Set-VMNetworkAdapterVLAN –VMName $VMNAme –Access –VLANID 100
Explore different use cases for Hyper-V virtual switch extensions
Navigate improvements to Windows Server 2016 Hyper-V Manager
Dig Deeper on Microsoft Hyper-V management
Related Q&A from Nirmal Sharma
Use the Get-EventLog PowerShell cmdlet with the desired parameters to retrieve a Hyper-V event log. This command gets errors and warnings and exports...continue reading
PowerShell commands save time and enable admins to migrate multiple VMs outside a Hyper-V failover cluster from one host to another, as well as VMs ...continue reading
System Center Orchestrator provides Run .Net Script activity, which can be used to call PowerShell scripts, but there are limitations you should know.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.