Tech

How to create multiple external network adapters on Hyper-V server with VLAN

Hyper-V virtual switch only allows to create just one external network adapter bound to the physical adapter. However, we can create virtual network adapters using below PowerShell command and bind it to the existing external switch. We can also add VLAN ID to this adapter to route traffic.

Prerequisites

  • Hyper-V server with at least one physical network adapter
  • PowerShell

Steps

  1. Open PowerShell with administrator privileges.
  2. Create a virtual network adapter using the following command:
Add-VMNetworkAdapter -ManagementOS -Name <adapter_name> -SwitchName <external_switch_name>
PowerShell
Add-VMNetworkAdapter -ManagementOS -Name Private -SwitchName External
  1. Add a VLAN ID to the virtual network adapter using the following command:
Set-VMNetworkAdapterVlan -ManagementOS -Access -VlanId <vlan_id> -VMNetworkAdapterName <adapter_name>
PowerShell
Set-VMNetworkAdapterVlan -ManagementOS -Access -VlanId 4001 -VMNetworkAdapterName Private
  1. Assign the virtual network adapter to a virtual machine. To do this, open Hyper-V Manager, right-click the virtual machine, and select Settings. In the Settings window, click Add Hardware and select Network Adapter. In the Network Adapter window, select the virtual network adapter you created in step 2 and click OK.

  2. Configure the IP address and other network settings for the virtual network adapter on the virtual machine.

Once you have completed these steps, the virtual machine will be able to communicate with other devices on the network using the VLAN ID you specified.

Example

The following example shows how to create two external network adapters on a Hyper-V server with VLAN:

PowerShell
# Create the first virtual network adapter
Add-VMNetworkAdapter -ManagementOS -Name Private1 -SwitchName External

# Add VLAN ID 1001 to the first virtual network adapter
Set-VMNetworkAdapterVlan -ManagementOS -Access -VlanId 1001 -VMNetworkAdapterName Private1

# Create the second virtual network adapter
Add-VMNetworkAdapter -ManagementOS -Name Private2 -SwitchName External

# Add VLAN ID 2001 to the second virtual network adapter
Set-VMNetworkAdapterVlan -ManagementOS -Access -VlanId 2001 -VMNetworkAdapterName Private2

# Assign the first virtual network adapter to a virtual machine
Assign-VMNetworkAdapter -VMName VM1 -VMNetworkAdapterName Private1

# Assign the second virtual network adapter to a virtual machine
Assign-VMNetworkAdapter -VMName VM2 -VMNetworkAdapterName Private2

Leave a Reply

Your email address will not be published. Required fields are marked *