Windows – How to create a NAT Switch on Hyper-V Manager application on Windows 10

hyper-vhyper-v-managernat;windows 10

I want to create a Hyper-V NAT Switch. I am using Hyper-V Manager application on Windows 10. I only see there are 3 types of Switch: External, Internal, and Private.

My question is where is NAT Switch type? Is it Internal Switch type? Thank you!

Best Answer

The default switch created by Hyper-V during install is NAT, but you can't configure it. Internal isn't NAT, it's just a regular switch with limited connectivity between the host and VMs.
If you just want basic NAT, use PowerShell, use the following commands:

New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal

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

New-NetNAT -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 192.168.0.0/24

For more information on NAT in Hyper-V, see: https://www.petri.com/using-nat-virtual-switch-hyper-v

If you want a configurable NAT, a better solution is to install and configure a small router VM with an OS like ipFire, pfSense, or your favorite Linux if you have the skills to configure it.

  1. Create an external virtual switch called External Access and connect to your host’s network.

  2. Create an internal virtual switch called Internal Lab.

  3. In Hyper-V Manager and click New –> Virtual Machine.

  4. Click Next to begin the wizard, enter the info in the fields and click Next when finished.

    1. Name: Lab Router
    2. Generation: Generation 1
    3. Startup memory: 512MB, uncheck Use Dynamic Memory
    4. Connection: Select External Access
    5. Virtual Hard Disk: accept defaults and click Finish
  5. Select Lab Router from Virtual Machines and click Settings.
    1. Select Network Adapter and click Add
    2. Select Internal Lab from Virtual Switch and click Apply
    3. Select DVD Drive, then select Image file.
    4. Click Browse and go to the location where the IPFire ISO is stored. Double-click the ISO. Click OK.
  6. Start the Lab Router VM.
    1. Click Start, then Connect.
  7. Install IPFire.
    1. Press Enter to begin the installation. Note: Window title will appear before instructions for this section.
    2. Language selection: Press Enter to accept English
    3. IPFire: Press Enter to Start installation
    4. License Agreement: Press tab to move to license acceptance box, then press the spacebar to accept. Press tab and Enter to complete.
    5. Disk Setup: Press Enter to accept and Delete all data
    6. Filesystem Selection: Press tab and Enter to accept the default.
    7. Congratulations: Press Enter to reboot
  8. Configure IPFire Pre-config info.
    1. While IPFire is rebooting, we need to determine which NIC’s MAC address is the External Lab’s.
    2. In the Hyper-V Manager with Lab Router selected, click Settings.
    3. Click on plus (+) next to Network Adapter External Access, then click Advanced Features to view the adapters MAC.
    4. Leave this window open, or make note of the MAC as we will need it soon.
  9. Configure IPFire
    1. Keyboard Mapping: Press Enter to select the default mapping.
    2. Timezone: Choose the correct timezone and press enter. Hint: pressing a letter will jump to that section. US Pacific (press P and arrow to PST8PDT) can be found this way quickly.
    3. Hostname: Press Enter twice to accept the default, ipfire.
    4. Domain name: Press Enter twice to accept the default.
    5. Root password: Enter a memorable password, tab to the verification field, and tab again to OK. Press Enter. Hint: no characters will appear when entering the password.
    6. Admin password: Enter a memorable password, tab to the verification field, and tab again to OK. Press Enter. Hint: no characters will appear when entering the password. Extra hint: for our lab, this can be the same password as the root account for simplicity.
    7. Network configuration: network configuration type: GREEN + RED should already be selected.
    8. Arrow key down to select Drivers and card assignments, press Enter
      1. Assigned cards: GREEN: Press Enter to select. Hint: the GREEN network is our Internal Lab network.
        1. Choose the card that does NOT have the MAC from step 8.3. Use the arrow key to highlight and press Enter
      2. Assigned cards: use the arrow keys to highlight RED, and press Enter
        1. Press Enter to select the remaining card.
      3. Assigned cards: press tab to move and highlight Done. Press Enter
    9. Arrow key down to select Address settings and press Enter
      1. Address settings: GREEN. Press Enter to reconfigure
        1. Warning: press Enter. Hint: we are not connected remotely, so this does not apply
        2. Interface GREEN: IP Address: 172.16.1.1 Network mask: 255.255.255.0 Press tab to move between fields, press Enter when complete
      2. Address settings: RED: Press Enter to reconfigure.
        1. Down arrow key to select DHCP, press spacebar to select. Tab to OK and press Enter. Hint: our external network will use the existing network DHCP server
      3. Address settings: Press tab to move to Done, press Enter.
    10. Arrow key down to Done and press Enter. Hint: we do not need to set the DNS and Gateway settings, the DHCP option selected above in 9-2 will autopopulate this for the RED network.
    11. DHCP server configuration: We will use the DHCP and DNS services on our Windows Server VM that we will set up later.
      1. Tab to OK and press Enter to leave the IPFire DHCP server unconfigured.
    12. Setup is complete: Press Enter. IPFire will reboot.
    13. IPFire/Lab Router VM should remain running.
    14. Close the Lab Router settings window, if needed.
  10. For the VMs that you want to use NAT, make sure to select Internal Lab. This will route all traffic through the ipFire VM. Note that you must have this VM running for connectivity.

--if there are errors in the formatting, please comment. I copied this from a previous document I created outside of superuser--

Source: https://smudj.wordpress.com/2019/03/18/the-poor-techs-hyper-v-lab-setup/

Related Question