Skip to content

Instantly share code, notes, and snippets.

@mreferre
Last active June 8, 2023 10:08
Show Gist options
  • Save mreferre/8dd8cd0025880ada9f5b53d64df5210e to your computer and use it in GitHub Desktop.
Save mreferre/8dd8cd0025880ada9f5b53d64df5210e to your computer and use it in GitHub Desktop.
PS commands to create a Hyper-V internal switch and NAT rules
# the following 3 lines of PowerShell creates an Internal Switch on Hyper-V (https://www.petenetlive.com/KB/Article/0001384)
New-VMSwitch -SwitchName "NAT-Switch" -SwitchType Internal
New-NetIPAddress -IPAddress 192.168.200.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NAT-Switch)"
New-NetNAT -Name "NAT-Network" -InternalIPInterfaceAddressPrefix 192.168.200.0/24
# the following line of PowerShell creates a DNAT rule (80->80) from the outside into a VM (previously created an running on the Switch with IP .10) (https://www.petri.com/create-nat-rules-hyper-v-nat-virtual-switch)
Add-NetNatStaticMapping -ExternalIPAddress "0.0.0.0/24" -ExternalPort 80 -Protocol TCP -InternalIPAddress "192.168.200.10" -InternalPort 80 -NatName NAT-Network
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment