Skip to content

Instantly share code, notes, and snippets.

@wcarhart
Created October 22, 2019 18:13
Show Gist options
  • Save wcarhart/48ce5d7e14a8172352db62af9705c183 to your computer and use it in GitHub Desktop.
Save wcarhart/48ce5d7e14a8172352db62af9705c183 to your computer and use it in GitHub Desktop.
Add Network NAT for Hyper-V VM
# list all VMSwitches
Get-VMSwitch
# for each VMSwitch, do the following:
Remove-VMSwitch <VM_SWITCH_NAME>
# list all NetNATs
Get-NetNAT
# for each NetNAT, do the following:
Remove-NetNAT <NETNAT_NAME>
# create a VMSwitch for our NAT
New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal
# configure NAT switch to be the gateway for your hardware
# Make sure to use an address range that does not conflict with your internal network schema.
# For example, if the address on your internal network use 192.x.x.x, you should use 10.x.x.x
# when setting up the NAT network. If both 192.x.x.x and 10.x.x.x are in use, you can use 172.x.x.x,
# or essentially any other address range that will not cause conflicts
New-NetIPAddress -IPAddress 192.168.1.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
# configure NAT network
# We can specify the prefix as '24' to allocate 256 (x.x.x.0 to x.x.x.255) addresses in our NAT
New-NetNAT -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 192.168.1.0/24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment