Thursday, February 13, 2014

Accessing a Web Server on a Virtual Box Ubuntu Guest from the Host Server

I do a lot of development of web applications in VirtualBox virtual machines running Ubuntu. Although I could (and sometimes do) set up the virtual machine to have multiple monitors, I usually don't, instead leaving one monitor for the host OS (Win7) and another for the VM.  So it's handy for me to be able to run a browser on the host OS and access a web application on the VM. In VirtualBox, I accomplish this with Port Forwarding.

Go into settings for the VM and select Network->Advanced and click Port Forwarding.

Then enter the IP address of your host machine, the port to forward, the IP address of the guest and the port the web application runs on.The example below sets up forwarding from http://localhost:8080 to a web application running on port 8080 (Tomcat in this case) on the VM: