Unable to access the web server within hyper-v from internet [duplicate]

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


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