How to create a NAT-Switch on Hyper-V with PowerShell

NAT is a technology to convert IP addresses. If you have a test environment then it might be necessary that your VMs need an internet connection and that you don’t want to use the external switch for that. In this blog post I will cover this topis and show you how you can create a NAT-Switch in Hyper-V in less than 3 minutes. Let’s go.

The following code sample creates a NAT switch for the address range /24. Please note that you need to adapt the code to your environment. Read the code sample carefully and fill in your desired netword range. Take also care of the network card id of your host network adapter which is ceratainly different from mine.



Hyper-V Host:
VMs IP-Range: /24


# Create a new NAT-Switch
New-VMSwitch -Name NAT-Switch -SwitchType Intern

# Retrieve the Interface ID of your NAT-Switch

# Configure the first address of /24 on NAT-Switch (Note the InterfaceIndex retrieved above)
New-NetIPAddress -IPAddress -PrefixLength 24 -InterfaceIndex 32

# Activate NAT
New-NetNat -Name MyNAT -InternalIPInterfaceAddressPrefix

# Check NAT 

Have fun with your newly created Hyper-V network with NAT enabled.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.