How to setup NAT network for Hyper-V guests?
Windows 10 Hyper-V has NAT (Network Address Translation) network
feature, but it needs to setup using PowerShell now. I will show you
step by step instructions how to do it. NAT Switch provides Internet
access to the VM without creating External Switch (linking the switch to
physical wired or wireless adaptor).
Before we start, here are the requirements to prepare it ahead of time.
1. IP Network to be used in Guests. You need to find a subnet that is not being using in your Office network. If you are setting up on your Home, you can choose any subnet that is not used in your home. E.g., 192.168.200.0/24
2. Guest VMs are needed to assign IP address/subnet/gateway manually from the subnet you choose on requirement 1 above. Or you may need to setup in DHCP server in one of the Guest VMs for automatic IP assignment. If you only have one or two guest VMs, you may set the IP address manually on NICs.
Now the step by step instruction.
E.g.,
Guest VM 1:
IP Address: 192.168.200.11
Subnet: 255.255.255.0
Gateway: 192.168.200.1
DNS: 4.2.2.2 and 8.8.8.8 (or your own DNS server from the office network).
Guest VM 2:
IP Address: 192.168.200.12
Subnet: 255.255.255.0
Gateway: 192.168.200.1
DNS: 4.2.2.2 and 8.8.8.8 (or your own DNS server from the office network).
That’s all. By now you guests should have access to External networks and Internet.
Hope this helped you. Leave me a reply below.
Before we start, here are the requirements to prepare it ahead of time.
1. IP Network to be used in Guests. You need to find a subnet that is not being using in your Office network. If you are setting up on your Home, you can choose any subnet that is not used in your home. E.g., 192.168.200.0/24
2. Guest VMs are needed to assign IP address/subnet/gateway manually from the subnet you choose on requirement 1 above. Or you may need to setup in DHCP server in one of the Guest VMs for automatic IP assignment. If you only have one or two guest VMs, you may set the IP address manually on NICs.
Now the step by step instruction.
Step 1: Open PowerShell with Administrative privileges.
Search PowerShell in Start menu search, right click on PowerShell and choose More ==> Run As Administrator.Step 2: Create Hyper-V internal only switch.
Run this command on the PowerShell.New-VMSwitch –SwitchName “NAT-Switch” –SwitchType Internal –Verbose
Step 3: Find the Interface Index number
Type this cmdlet and note down the interface index (ifIndex) for NAT-Switch adaptor.Get-NetAdapter
Step 4: Create NAT Gateway
Run this cmdlet. Replace- IP Address (gateway) with your own (should be from the network subnet you chose in the requirements section above)
- PrefixLength is the subnet mask number for the subnet you chose
- Interface index you noted down on previous step.
New-NetIPAddress –IPAddress 192.168.200.1 -PrefixLength 24 -InterfaceIndex 16 –Verbose
Step 4.1: Create NAT Network
Run this cmdlet and replace InternelIPInterfaceAddressPrefix with your chosen network.New-NetNat –Name NATNetwork –InternalIPInterfaceAddressPrefix 192.168.200.0/24 –Verbose
Step 5: Connect your VM to the NAT-Switch
You may manually assign the Guest NIC to the “NAT-Switch” which we created in Step-2. Or you may run this cmdlet to assign NIC from all Guest VMs to the “NAT-Switch”Get-VM | Get-VMNetworkAdapter | Connect-VMNetworkAdapter –SwitchName “NAT-Switch”
Step 6: Assign IP Address to the NICs in Guests
Open NIC properties in your Guest VMs, Assign IPv4 addresses from the network subject you setup in Step-4. Or run DHCP server from one of your Guests to dish IP address automatically.E.g.,
Guest VM 1:
IP Address: 192.168.200.11
Subnet: 255.255.255.0
Gateway: 192.168.200.1
DNS: 4.2.2.2 and 8.8.8.8 (or your own DNS server from the office network).
Guest VM 2:
IP Address: 192.168.200.12
Subnet: 255.255.255.0
Gateway: 192.168.200.1
DNS: 4.2.2.2 and 8.8.8.8 (or your own DNS server from the office network).
That’s all. By now you guests should have access to External networks and Internet.
Hope this helped you. Leave me a reply below.
Comments
Post a Comment