Hyper V Network

My external virtual switch is configured as follows:

enter image description here

Interl(R) Ethernet Connection (2) I219-V is my network card listed in Device Manager. My external virtual switch is selected as the network adapter for my virtual machine:

enter image description here

2 Answers

3

Hyper-V Network Adapter: You want to set up an external virtual switch in Hyper-V, if you haven't already and assign that to your VM. This will allow your VM access to your host's network. You don't want to use the default NAT adapter with Hyper-V, it's not configurable and doesn't allow port forwarding.

To set up an external virtual switch:
In Hyper-V Manager, click Virtual Switch Manager, select External, click Create Virtual Switch. Under External network, select the network card that is connected to your network, Allow management OS to share this network adapter should remain checked. Click OK. Assign this new virtual switch to the Ubuntu VM. Note: this will temporarily disconnect your host PC from the network while the virtual switch is installing.

NAT: You should already have NAT enabled on your firewall/router. It's not a good idea to be directly connected to the internet. You don't need NAT on your Windows 10 host for this to work, it will only add to the complexity.

Static IP: You would pick this based on your network. You should pick a value that's outside your DHCP scope, but in the same subnet (192.168.0.x).

Port forwarding: Use the port forwarding on your router/firewall to handle the port forward. Use an external virtual switch and assign your VM an IP from your regular network. Configure the port forwarding for the Port/IP address in your router/firewall.

Configure Ubuntu for static IP: You do this in your VM, not in an Hyper-V component. In Ubuntu, go to Settings-->Network. Click the gear icon next to the wired network connection. Click the IPv4 tab, click Manual, and enter the IP settings specific to your network. The subnet mask, gateway, and DNS values should be the same as the host's.

See this link for pictures of above: https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux

  • I created external network adapter and the dynamic IP address of my Ubuntu machine is now 192.168.0.103, see EDIT1. What should I specify as Netmask and Gateway in Ubuntu Settings->Network->IP4 page? If I leave them empty the internet connection is lost. Jun 5 '19 at 21:09
  • 1
    Those should be correct, netmask and gateway (and DNS) will be the same as the host as long as you're using an external virtual switch. Verify that your external switch is connected to your active network card.
    – essjae
    Jun 5 '19 at 22:00
  • 1
    No, you don't need to use adapter sharing. Look in the Hyper-V Manager under Virtual Switch Manager. Click on the virtual switch you've created, you can't use the default switch for this, and verify that it's set to "external network" and your network card is listed there. "Allow management operating system to share this network adapter" should also be checked.
    – essjae
    Jun 5 '19 at 23:26
  • 1
    This is the virtual switch you want to assign to the VM: Ethernet adapter vEthernet (External Virtual Switch)
    – essjae
    Jun 5 '19 at 23:36
  • 1
    That looks correct. Does the Ubuntu VM get an IP from DHCP with that config?
    – essjae
    Jun 6 '19 at 16:11
2

Just as a note, you CAN do static NAT mapping without putting your VM on your physical network, this allows you to use your host to be the only device on the phyiscal network while keeping your other VMs behind your host's firewall/segmented and share the same MAC as host which is often needed in universities, schools, dorms, etc.

https://petri.com/create-nat-rules-hyper-v-nat-virtual-switch