Share via


How to connect a 2016 Hyper-V VM to multiple vLANs via a single physical NIC

Question

Monday, February 25, 2019 8:02 PM

A physical switch is configured with four tagged vLANs on a single port.

The single physical switch port is connected to a physical box with a single physical NIC.

The box is running Hyper-V Core 2016.

A single vSwitch (External) uses that single physical NIC.

A single VM running Server 2016 Standard is using that vSwitch.

I want that VM to be able to communicate with those 4 vLANs.

I've seen a thousand and one ways described but none exactly what I want.

A little help?

All replies (6)

Monday, February 25, 2019 8:45 PM âś…Answered

Fundamentally, there are only two ways.

If the VM needs a distinct endpoint presence in all four VLANs (most common), then you need to add a total of four network adapters to the VM and assign each to the necessary VLAN. You can do that in the various GUIs or in PowerShell (first Add-VMNetworkAdapter, then Set-VMNetworkAdapterVlan with -Access and -VlanId.

If you want the VM to receive frames with the 802.1q VLAN tag intact (uncommon, only valid if you're going to run a firewall or similar Ethernet-aware application), then you must use the Set-VMNetworkAdapterVlan cmdlet with the -Trunk and -AllowedVlanIdList on the virtual machine's virtual network adapter.

Eric Siron
Altaro Hyper-V Blog
I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.


Thursday, February 28, 2019 6:51 AM

Hi,

Just check the situation about your issue.

Best Regards,
Frank

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Thursday, February 28, 2019 9:13 PM

Using the following I'm able to create the 4 NICs easily enough.

Add-VMNetworkAdapter -ComputerName "HVHost" -VMName "VM1" -Name "NICvLAN100" -SwitchName "Onboard" -StaticMacAddress "00:11:22:33:44:55"
Add-VMNetworkAdapter -ComputerName "HVHost" -VMName "VM1" -Name "NICvLAN200" -SwitchName "Onboard" -StaticMacAddress "00:11:22:33:44:56"
Add-VMNetworkAdapter -ComputerName "HVHost" -VMName "VM1" -Name "NICvLAN300" -SwitchName "Onboard" -StaticMacAddress "00:11:22:33:44:57"
Add-VMNetworkAdapter -ComputerName "HVHost" -VMName "VM1" -Name "NICvLAN400" -SwitchName "Onboard" -StaticMacAddress "00:11:22:33:44:58"

But this

Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapter "NICvLAN100" -Access -VlanId "100"
Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapter "NICvLAN200" -Access -VlanId "200"
Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapter "NICvLAN300" -Access -VlanId "300"
Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapter "NICvLAN400" -Access -VlanId "400"

Is belching out

Set-VMNetworkAdapterVlan : Cannot bind parameter 'VMNetworkAdapter'. Cannot convert the "NICvLAN100" value of type
"System.String" to type "Microsoft.HyperV.PowerShell.VMNetworkAdapterBase".
At line:1 char:90
+ ... HVHost" -VMName "VM1" -VMNetworkAdapter "NICvLAN100" -Access ...
+                                                      ~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-VMNetworkAdapterVlan], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.HyperV.PowerShell.Commands.SetVMNetworkAdapterV
   lan

Thursday, February 28, 2019 9:16 PM

Use -VMNetworkAdapterName in this context, not -VMNetworkAdapter.

Eric Siron
Altaro Hyper-V Blog
I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.


Thursday, February 28, 2019 9:59 PM

Doh!

I remember reading that but didn't have a context to apply why ... now I know.  ... and knowledge is power!

Thank you for your help.

Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapterName "NICvLAN100" -Access -VlanId "100"
Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapterName "NICvLAN200" -Access -VlanId "200"
Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapterName "NICvLAN300" -Access -VlanId "300"
Set-VMNetworkAdapterVlan -ComputerName "HVHost" -VMName "VM1" -VMNetworkAdapterName "NICvLAN400" -Access -VlanId "400"

Friday, March 1, 2019 3:11 AM

Hi,

Thanks for your update

I am glad to hear that your issue was successfully resolved.

Best regards,
Frank

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]