VirtualBox is a free, lightweight virtual machine simulator from Sun. The current version is 3.0.10.
One of the uses of VirtualBox is to run a web server or other application from a virtual operating system on your computer, whether it be Windows, Linux, or Mac.
So, the point of this short post is to describe how to access your web server from your host machine. For whatever odd reason, I simply could not find this documented *anywhere* that was simple. This requires no installation of extra software or configuration of anything on your computer or on your virtual server.
Ok, I’m assuming that you already have your server installed.
- Shut it down if its running.
- Open up Virtual Box. In the left panel, select your VM and then click the yellow Settings button above it.
- In the new view, click on the Network button off to the right along the top.
- By default, Adapter 1 should already be selected. If not select it, or if you are configuring a different adapter, select that one.
- You should see menus called Adapter Type, Attached To, and Name. Name is probably greyed out.
- Under Attached To, select Bridged Adapter. The Name menu should now be clickable.
- Under the Name menu, select the network adapter that your computer is using for its internet connection. I am on a Mac on wireless, so my network adapter is en1: Airport. Yours might be one of the others if you are connected via ethernet.
- Hit OK, and this window will go away.
- Now start your VM image and log in.
- Once it is started up, you have to find the IP address that the VM is now using.
- If you are running a Linux server like Ubuntu, type “ifconfig” on the command line. Look for “eth0” and the “ifnet addr” near it. In my case, it is 126.96.36.199.
- If you are running Windows, open your command prompt and type “ipconfig”. Look for a similar type of IP address.
- The IP address you found will be the one that you use to contact your virtual web server.
- Open a browser and type that number in as the address. If your server is up and running, you should now see a web page from it.
As an added bonus, its easy to configure a local name that points to this IP address and makes it easy to access your web page in the future. The steps are nearly identical for Mac, Linux, and Windows users. Since I am on a Mac, I will describe the process for us. For Windows users, do a quick search on where to find your Hosts file. The information I describe here applies, but your hosts file is in a different location.
- Mac users: Open a terminal.
- Type ‘sudo pico /etc/hosts’ and enter.
- Somewhere at the end of the file, add something like “localubuntu 192.168.0.7”. Of course, “localubuntu” is the address I want to use. Feel free to name it whatever you like. Also, the IP address has to match the one that you found in the earlier steps with “ifconfig” or “ipconfig”.
- Hit control-o and enter to save the changes. Closing the terminal window will save the changes system wide. No reboot should be necessary.
- Now go back to a browser and try going to “localubuntu” or whatever you named yours and you should now be hitting your web server.
Feel free to leave comments, suggestions, or questions about any of this.