'Can't port forward/port map from Hyper-V VM to Host IP Address via Virtual Switch NAT

I configured my network for my Ubuntu VM in Hyper-V such that it is connected to an internal network virtual switch, which is connected to my working Ethernet internet connection through Internet Connection Sharing (Network Connections > Ethernet > Properties > Sharing). Here's a picture of the setting in question:

enter image description here

I selected the virtual adapter for the internal network in the dropdown, and it assigns the internal network an IP of 192.168.137.1, for the gateway, and I configured my Ubuntu VM to operate on a static IP within the 192.168.137.XXX range. I decided to choose an internal network for the virtual switch because I don't want to modify the static IP address of the host machine, which I cannot keep the same for some reason if I select external network to share the internet connection that way.

The problem is that I'm hosting the VM for the purposes of running docker services, I'm set on doing it this way, all I need to do is be able to expose port 3000 for example from the internal NAT IP of 192.168.137.2:3000 to my host IP address, 192.168.0.2:3000. I've put in the following commands:

New-NetNat -Name UbuntuNAT -InternalIPInterfaceAddressPrefix 192.168.137.0/24

Add-NetNatStaticMapping -NatName UbuntuNAT -Protocol TCP -ExternalIPAddress 0.0.0.0 -ExternalPort 3000 -InternalIPAddress 192.168.137.2 -InternalPort 3000

And it worked for a second, before the VM lost its internet connection and now will no longer connect to the internet. Perhaps creating the NAT on 192.168.137.0/24 is messing up the internet connection sharing somehow? I don't know any alternative way I could port map the internal NAT. I need to find a way to connect the internal NAT to the host machine's IP, or an alternative way of doing this whole setup if this method isn't practical.



Solution 1:[1]

Control Panel > Network and Internet > Network Connections > Change adapter settings

Select the connection you want to share that's connected to the Internet, go to Properties, Sharing tab, check Allow other users to connect to this Internet connection, select the virtual switch internal network in the dropdown, then select Settings to port forward. Use the static IP for the VM in the address field.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 biotecher