How to Configure Network Address Translation (NAT) in Windows 11 Using PowerShell

When running local development environments, virtual machines (VMs) in Hyper-V, or Windows Server containers, administrators frequently configure internal virtual switches to isolate guest environments from the physical corporate local area network (LAN). However, internal virtual switches do not automatically provide routing or internet access: guest machines can communicate with the Windows host, but cannot reach external internet endpoints or receive traffic from outside networks.

Windows 11 and Windows Server include the native NetNat PowerShell module. By establishing a software-defined Network Address Translation (NAT) gateway on an internal virtual switch, administrators can route outbound traffic through the host’s physical network adapter and establish static port-forwarding rules for guest services without requiring third-party routing software.

Creating an Internal Virtual Switch in Hyper-V

Open PowerShell as an Administrator. First, provision an internal virtual switch dedicated to your NAT network:

New-VMSwitch -Name "NATSwitch" -SwitchType Internal

Windows generates a corresponding virtual network adapter on the host operating system named vEthernet (NATSwitch). Verify its creation:

Get-NetAdapter "vEthernet (NATSwitch)"

Assigning the Host Gateway IP Address

To act as the default gateway for guest virtual machines, the host adapter must hold a static IP address on your chosen private subnet (for example, 192.168.100.1/24):

New-NetIPAddress -IPAddress 192.168.100.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"

Provisioning the NAT Network with New-NetNat

Create the NAT gateway object, specifying the internal subnet prefix that will be translated:

New-NetNat -Name "InternalNAT" -InternalIPInterfaceAddressPrefix "192.168.100.0/24"

Important: The Windows TCP/IP stack supports only one NAT network object per host. Attempting to create a second NAT object will fail. You can verify your active NAT gateway configuration at any time:

Get-NetNat

Configuring Guest Virtual Machines

Connect your Hyper-V virtual machines or containers to the NATSwitch. Within each guest operating system, configure static network properties matching the subnet:

  • IP Address: Any unassigned IP within the subnet (e.g., 192.168.100.10).
  • Subnet Mask: 255.255.255.0 (Prefix 24).
  • Default Gateway: The host adapter IP (192.168.100.1).
  • DNS Servers: Public resolvers such as 1.1.1.1 or 8.8.8.8.

Guest virtual machines can now access the external internet, with outgoing packets translated dynamically to your host’s primary physical IP address.

Configuring Inbound Port Forwarding (Static Mappings)

Because NAT shields guest machines behind a private subnet, external devices cannot initiate direct connections to internal VM services. Use Add-NetNatStaticMapping to map an external host port to an internal guest port:

# Forward external port 8080 to an internal web server on port 80
Add-NetNatStaticMapping -NatName "InternalNAT" -Protocol TCP -ExternalIPAddress 0.0.0.0 -ExternalPort 8080 -InternalIPAddress 192.168.100.10 -InternalPort 80

# Forward external port 2222 to an internal SSH server on port 22
Add-NetNatStaticMapping -NatName "InternalNAT" -Protocol TCP -ExternalIPAddress 0.0.0.0 -ExternalPort 2222 -InternalIPAddress 192.168.100.10 -InternalPort 22

Review all active port forwarding rules:

Get-NetNatStaticMapping

Monitoring Sessions and Removing NAT Configurations

To inspect active translated connections and open socket states:

Get-NetNatSession

When decommissioning a test network, remove the static port mappings and the NAT object cleanly:

# Remove a specific static mapping by its identifier
Get-NetNatStaticMapping | Where-Object ExternalPort -eq 8080 | Remove-NetNatStaticMapping -Confirm:$false

# Remove the entire NAT gateway
Remove-NetNat -Name "InternalNAT" -Confirm:$false

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.