Q. How do I create a NAT forwarding switch with Hyper-V in Windows 10 and Windows Server 2016?
A. Windows 10 and Windows Server 2016 adds the native ability for a NAT forwarding Hyper-V switch which is a requirement for containers that need NAT. In the RTM of Windows 10 and early Windows Server 2016 builds the switch was created using a SwitchType of NAT however this has changed in the latest builds. The PowerShell below creates a new NAT switch using subnet 192.168.1.0/24.
New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal
New-NetIPAddress –IPAddress 192.168.1.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
New-NetNat –Name NATnetwork -InternalIPInterfaceAddressPrefix 192.168.1.0/24
It's also possible to create NAT static forwarding rules which enables traffic to the host to be sent to the VM.
#Map the host IP to port 80 on VM 192.168.1.10 through switch
Add-NetNatStaticMapping -NatName NATnetwork -Protocol TCP -ExternalIPAddress 0.0.0.0 `
-InternalIPAddress 192.168.1.10 -InternalPort 81 -ExternalPort 81
0 comments
Hide comments