Heads Up! This post is now very outdated. There’s a MUCH easier way to access localhost in VirtualBox.
Last week I explained how to convert the IE6 – IE8 VirtualPC disk images to VirtualBox on the Mac. This week I noticed something critically wrong, I can’t access localhost or any LAN IP address from inside VirtualBox. This is a huge problem if you want to do local testing in IE.
The problem is that Mac support is still rather early with VirtualBox and they only provide a NAT networking option. I wont explain what NAT is because I don’t completely understand it myself. If you’re on Linux or Windows you can simply use the bridged network and it’ll work fine.
As with any problem, there is a solution! You could go buy VMWare Fusion, which should support this out of the box, but what’s the fun and challenge in that? The fun and free solution is to use a service called DynDNS.
What is DynDNS
If you’re like most people your ISP gives you a dynamic IP, which means that your home network doesn’t always have the same IP address and every so often your ISP will assign you a different one. DynDNS will give you a free domain name that always points to your ever changing home network IP address.
This means that when you’re done you’ll load a URL like “http://<you>.dyndns.org/” instead of “localhost” inside VirtualBox. This also assumes that you have some sort of web server running on your computer to serve up the pages.
Step 1 – Web Server
Setup a simple web server like Apache or the free version of LightSpeed (free version is at the bottom of the download page).
Make sure the server is installed and running properly before proceeding.
Step 2 – DynDNS Account
Go to DynDNS, register an account and create a new host. The site has good help sections to assist you through any issues or questions you run into. (see the DynDNS How-To section)
After creating the new host, download, install and run the DNS update program. This will update the service with your new IP address every time it changes.
Step 3 – Router
If your network uses a router, you might need to update it’s settings to let the requests through to your computer inside the network. At this point it is important to realize that your router has the “main” IP, which is provided by your ISP, and each computer inside your network will get their own “internal” IP address, provided by the router itself.
First test the new DynDNS URL you created. When you load the URL in your browser does it show pages from your local web server or does the browser sit there and mock you as it endlessly spins the “loading” animation?
If your web server didn’t load anything, you might need to alter your firewall settings and/or setup port forwarding in your router. Start by checking your router manual for information on how to login and change settings on it. On my SMC wireless router after logging in I found the settings I needed under Advanced Setup > NAT > Virtual Server. There I entered the last number from my “internal” IP address (IP on my computer) and the port that should direct to that computer. So if my internal IP is 220.127.116.11 and my web server is setup to respond to port 80, I enter “53” and “80” into the fields.
Step 4 – Static Internal IP
If you had to setup port forwarding in the last step, you should also create a static internal IP on your computer. Otherwise next time you restart your computer it’s IP might be different and your URL wont work.
This step is surprisingly simple:
- Open your network preferences
- Go to the network you use (in my case “Airport”)
- Click Advanced (or similar button — I’m using Mac Leopard)
- Go to the “TCP/IP” area.
- Change the dropdown menu from “Using DHCP” to “Using DHCP with manual address”
- Enter the internal IP address you added to the port forwarding setting in your router.
If you have any problems with the setup, check out the troubleshooting page at DynDns.
Now you should be able to access your local computer from inside VirtualBox with your new URL.