Connect with us

Gadgets

How to Create Hyper-V vSwiches, VMs, and vNICs in Windows 11

[ad_1]

Read this guide to learn how to create virtual swicthes, virtual machines and virtual Network Interface cards (vNICs) with Hyper-V enabled in Windows 11.

Step 1: Install Hyper-V Role in Windows 11

Open PowerShell as Administrator and run the command below

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All

The command installs Hyper-V and all its management tools, including its PowerShell module. When installation finishes, PowerShell will prompt you to restart the computer – type Yes and press the Enter key to restart the computer.

Step 2: Create a Hyper-V Virtual Switch

When you create VMs in Hyper-V, their NICs connect to the network via an external Hyper-V virtual switch.

To create an External Hyper-V switch on a host run the command below. Before you run the command, run the Get-NetAdapter command to determine the name of the physical NIC on the host.

Replace the value in the “Name” colume of the Get-NetAdapter command with “Wi-fi” in my command.

New-VMSwitch -Name HPV-vSwitch -NetAdapterName "Wi-fi"

The command creates an External Hyper-V virtual switch called HPV-vSwitch and connects it to the Wi-Fi Network adapter on the Hyper-V host.

When you create a Hyper-V switch with a NIC, the IP address assigned to the NIC is transfered to the Virtual switch. In my example, I had assigned 192.168.0.150 to the Wi-Fi adapter.

When I created an External Hyper-V virtual switch that connects to the Wi-Fi adapter, the IP is automaticallt transfered to the virtual switch. To confirm this, open the TCP/IP IPv4 properties of the virtual switch. See the screenshot below for details.

open the TCP-IP IPv4 properties of the virtual switchopen the TCP-IP IPv4 properties of the virtual switch

Step 3: Create the Hyper-V Virtual Machines

The PowerShell commands below create multiple VMs with different configurations. See my explanations beneath the commands for what each command do.

#1. create IPMvESXi1 with 16 GB of RAM, set processor count and enable nested virtualization

New-VM -Name IPMvESXi1 -MemoryStartupBytes 16384MB -Generation 1 -NewVHDPath c:VMsIPMvESXi1.vhd -NewVHDSizeBytes 60GB | Set-VMProcessor -Count 2 -ExposeVirtualizationExtensions $true

#2. create IPMvESXi2 with 8 GB of RAM, set processor count and enable nested virtualization

New-VM -Name IPMvESXi2 -MemoryStartupBytes 8192MB -Generation 1 -NewVHDPath c:VMsIPMvESXi2.vhd -NewVHDSizeBytes 60GB | Set-VMProcessor -Count 2 -ExposeVirtualizationExtensions $true

#3. disable Dynamic Memory for IPMvESXi1 and IPMvESXi2

"IPMvESXi1", "IPMvESXi2" | ForEach-Object {Set-VMMemory $_ -DynamicMemoryEnabled $false}

#4. Create IPMviSCSI with 1GB RAM, set processor count to 1, disable Dynamic Memory

New-VM -Name IPMviSCSI -MemoryStartupBytes 1024MB -Generation 2 -NewVHDPath c:VMsIPMviSCSI.vhdx -NewVHDSizeBytes 60GB | Set-VMMemory -DynamicMemoryEnabled $false | Set-VMProcessor -Count 1

The first command, creates a Generation 1 VM with 16 GB RAM, 60GB of vritaul disk, 2 processor counts, and enables nested virtualization. Then, the second command creates a VM with similar specs as the first VM, except that the second VM is assigned 8 GB of RAM.

Enabling nested virtualization allows you to install a hypervisor like VMWAre ESXi or Hyper-V on a VM.

Meanwhile, the thrid command disables dynamic memory on the first two VMs. Disabling Dynamic memory is recommended if you’re using the VM as a hypervisor – a hypervisor requires a fixed RAM. Finally, command #4 creates a Generation 2 VM with 1 GB of RAM, 60GB of virtual hard disk and 1 processor count.

After running the above commands on your Hyper-V host, you should have the VMs shown in my screenshot below.

Create the Hyper-V Virtual MachinesCreate the Hyper-V Virtual Machines

Before proceeding, confirm that nested virtualzation is enabled on the two VMs by running the command below:

Get-VMProcessor -VMName IPMvESXi* | Select-Object VMName, ExposeVirtualizationExtensions

The command should return “True” on ExposeVirtualizationExtensions column for both VMs.

nested virtualzation is enabled on Hyper-V VMsnested virtualzation is enabled on Hyper-V VMs

Step 4: Create and Configure vNICs on the VMs

The final task is to create all the vNIC and configure MAC address spoofing on the VMs with nested virtualization enabled. Enabling nestedd virtualization means that you intend to install Hyper-V or VMWare ESXi on them.

MAC address spoofing allows the VMs on the nested VM to connect to the main host’s network. If you look at the beneath “Enable MAC address spoofing” checkbox on a Hyper-V VM, it reads “MAC address spoofing allows a virtual machine to change the source MAC address in outgoing packets to the one not assigned to them”

MAC address spoofing allows the VMs on the nested VM to connect to the main host's network. MAC address spoofing allows the VMs on the nested VM to connect to the main host's network.

In essence, since the VMs created in the “second” VM, they will traverse two virtual switches – MAC address spoofing allows makes that possble

If you plan to install ESXi on Hyper-V VMs, you must use Legacy vNIC – the available network driver only supports Legacy Hyper-V vNICs.

However, when we created the VMs, a non-legacy vNIC was added automatically. The first step is to remove the vNICs. To do that, run the command below:

"IPMvESXi1", "IPMvESXi2" | ForEach-Object {Remove-VMNetworkAdapter -VMName $_ }

After that, run these commands to create legacy vNICs and enable MAC address spoofing.

#Create the lagacy vNICs for IPMvESXi1 

"ESXiNIC1", "ESXiNIC12" | Foreach-Object {Add-VMNetworkAdapter -VMName IPMvESXi1 -Name $_ -IsLegacy $true -SwitchName HPV-vSwitch }

#enable MacAddress Spoofing

Get-VMNetworkAdapter -VMName IPMvESXi1 | ForEach-Object {Set-VMNetworkAdapter -VMName IPMvESXi1 -MacAddressSpoofing On}

#Create the lagacy vNICs for IPMvESXi2

"ESXiNIC1", "ESXiNIC12" | Foreach-Object {Add-VMNetworkAdapter -VMName IPMvESXi2 -Name $_ -IsLegacy $true -SwitchName HPV-vSwitch }

#enable MacAddress Spoofing

Get-VMNetworkAdapter -VMName IPMvESXi2 | ForEach-Object {Set-VMNetworkAdapter -VMName IPMvESXi2 -MacAddressSpoofing On}

Conclusion

Enabling the Hyper-V optional feature in Windows 11 provides IT pros a great opportunity to create labs for playing with different technologies. Once you enable Hyper-V, your next step willl be to creat a virtual switch.

After that, you create VMs and finally, network cards that will connect those VMs to the network.

In this guide, I showed how to perform these tasks, mainly with PowerShell commands. Using PowerShell commands makes these tasks faster.

I also showed how to enable nested virtualization and MAC address spoofing to allow you use VMs in the main host as hypervisors. Finally, if you intend to install VMWare ESXi on Hyper-V VMs, I also explained how to create Legacy vNICs.

[ad_2]

Victor Ashiedu

Source link