Q
Manage Learn to apply best practices and optimize your operations.

Configure Hyper-V virtual switches and assign VLAN IDs to VMs

Prepare Hyper-V to use the VLAN domain concept by configuring Hyper-V virtual switches and assigning VLAN IDs to VMs using either PowerShell cmdlets or Hyper-V Manager.

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

}

Next Steps

Explore different use cases for Hyper-V virtual switch extensions

Navigate improvements to Windows Server 2016 Hyper-V Manager

Use these PowerShell commands to do a Hyper-V health check

This was last published in September 2017

Dig Deeper on Microsoft Hyper-V management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What are your best practices for configuring Hyper-V switches?
Cancel

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close