Tuesday, 8 January 2019

Accessing website running on Ubuntu VM from Windows Host

So this might appear simple, but it does require a bit of attention and work. 

First of all, let us create the Ubuntu VM on Hyper-V using the "Quick Create" option. You can follow the details from here

Once you are through, you will have an Ubuntu VM running on Hyper-V with Enhanced Session mode which is actually quite nicer than doing all of the hacks on your own to get a better Remote Desktop experience. 

The network switch configured for the VM will be "Default Switch". Read more about it here This means that you should be able to ping the VM machine from Host (and vice-versa) using a domain name "mshome.net".


Once you are done, you can host/run a web application on the Ubuntu VM. I used VSCode to create a .NET Core MVC Web application and ran it. I configured the application to use "HostName" of the VM during startup so that .NETCore understands and allows the HostName for accessing the site - by default .NET core's web server does not allow other host names unless specified.


You should be able to access the web application using both the URLs on the VM. Right now, if you attempt to access the application from host VM, it will fail.

Configure Firewall

We need to configure firewall on the Ubuntu VM. I installed UFW application on the VM and allowed 5002 port. Here is the tutorial to achieve the same.

Once it is done, the application should be accessible using "VMName.mshome.net" host name.


Hope it helps.









No comments:

Post a Comment