This step-by-step guide explains how to install Hyper-V on AWS EC2 bare metal instances. Bare metal instances enable you to run legacy workloads that don't work in virtual environments, specialized workloads that need direct access to bare metal infrastructure, applications that have license restrictions, and applications that can take advantage of deep performance analysis tools.

Before we get started, keep the following points in mind:

  • Bare metal instances are not available for all the instance families, and all the bare metal instance types follow this naming convention: family-name.metal. For example, c5.metal.
  • VHDs are stored on EBS volumes attached to EC2 instances.

As a prerequisite, ensure there's a VPC with an internet gateway attached to it.

Spin up a bare metal EC2 instance with Hyper-V

Navigate to the AWS EC2 instances console, and click AMIs.

Select Public images.

Displaying public AMIs

Displaying public AMIs

Multiple AMIs are displayed for Windows Server 2012 R2, 2016, and 2019. These AMIs have the Hyper-V role pre-enabled.

Select the AMI you want and click Launch.

Selecting Hyper V AMI

Selecting Hyper V AMI

Then, you are prompted to Choose an Instance Type. Ensure that the instance type follows the naming convention family-name.metal.

Selecting an instance type

Selecting an instance type

Afterwards, you can configure the instance details, add storage, add tags, configure the security group associated with the instance, and finally, review your configuration before launching the instance.

Configure Hyper-V networking

We will be using an internal vSwitch to act as a NAT gateway for the Hyper-V guest VMs. In a nutshell, this will allow the guest VMs to access other network resources in the same VPC as the Hyper-V host using the Hyper-V host's IP address and port through the internal vSwitch, while the guest VMs use another IP address range for their internal communication.

To create the internal virtual switch, run the following PowerShell cmdlet:

New-VMSwitch -SwitchName "InternalSwitch" -SwitchType Internal 

Retrieve the network interface index of the virtual switch you just created, as you will need it in the next step. To do so, run the following PowerShell cmdlet:

Get-NetAdapter | where {$_.Name -match "InternalSwitch"} 
Retrieving the interface index

Retrieving the interface index

Next, configure the NAT gateway, which should be in a different CIDR block than the VPC CIDR block, using the following PowerShell cmdlet:

New-NetIPAddress -IPAddress 10.10.10.1 -PrefixLength 24 -InterfaceIndex 8 

This IP is used as the default gateway for the guest VM.

Then, create the NAT network using the following cmdlet:

New-NetNat -Name NATNetwork -InternalIPInterfaceAddressPrefix 10.10.10.0/24 

So far, we have created a virtual network for the Hyper-V guest VMs with a 10.10.10.0/24 address prefix and 10.10.10.1 as the NAT gateway. This is represented by the internal vSwitch we created earlier, which allows access to other network resources.

Configure DHCP for the guest VMs

This step is optional. You can actually start spinning up VMs by now; however, you will have to assign IPs manually to the VMs. If you want to have it automatically assigned, you can configure the DHCP server on the Hyper-V host.

To install the DHCP role, run the following PowerShell cmdlet:

Install-WindowsFeature -Name 'DHCP' -IncludeManagementTools 

To ensure that the DHCP server is bound to the Hyper-V virtual interface, navigate to the DHCP console, right-click the server, and choose Add or Remove Bindings. The Server Bindings Properties dialog box is displayed.

Verifying the DHCP server binding to the Hyper V virtual interface

Verifying the DHCP server binding to the Hyper V virtual interface

If the checkbox is not selected, select it and click OK.

To add a DHCP scope from which the guest VMs can get their IPs, run the following PowerShell cmdlet:

Add-DhcpServerv4Scope -Name VMs-IPs -StartRange 10.10.10.20 -EndRange 10.10.10.250 -SubnetMask 255.255.255.0 -State Active 

Finally, you need to configure the DHCP server options for Router and DNS Server, where the router IP is the NAT gateway IP created earlier, and the DNS server IP is the Amazon-provided DNS server in your VPC. (If you're using a custom DNS server in this VPC, then you will have to pass its IP instead.)

Set-DhcpServerV4OptionValue -DnsServer 172.31.0.2 -Router 10.10.10.1 

Now you can go ahead and start spinning up new VMs on the Hyper-V host.

Subscribe to 4sysops newsletter!

Conclusion

In this article, we've gone through how to run Hyper-V on AWS EC2 bare metal instances. If you’ve any additional questions, please mention them in the comments.

0 Comments

Leave a reply

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

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account