Skip to content

Instantly share code, notes, and snippets.

@johnrizzo1
Last active September 8, 2017 13:59
Show Gist options
  • Save johnrizzo1/e8f93c8c75a1cad438e60d6370e5bfde to your computer and use it in GitHub Desktop.
Save johnrizzo1/e8f93c8c75a1cad438e60d6370e5bfde to your computer and use it in GitHub Desktop.
Hyperv Nat Setup
$switchName = "nat_switch"
$network = "192.168.0.0"
$networkMask = "24"
$defaultGateway = "192.168.0.1"
New-VMSwitch -SwitchName $switchName -SwitchType Internal
$networkAdapter = Get-NetAdapter | where { $_.Name -eq "vEthernet ($switchName)" }
New-NetIPAddress -IPAddress $defaultGateway -PrefixLength $networkMask -InterfaceIndex $networkAdapter.ifIndex
New-NetNat -Name $networkAdapter.ifIndex -InternalIPInterfaceAddressPrefix $network/$networkMask
# References
# https://4sysops.com/archives/native-nat-in-windows-10-hyper-v-using-a-nat-virtual-switch/
# https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/setup-nat-network
# https://www.petri.com/configuring-vm-networking-hyper-v-nat-switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment