IP address-independent access to Mac virtual hosts from Parallels virtual machines

Like many other Mac-using web developers I use Parallels Desktop for testing in various versions of Internet Explorer. It works well, including accessing local development sites set up as virtual hosts in Apache on my Mac.

One thing that’s been bothering me for a long time, though, was that whenever my Mac got a new IP address I had to open the hosts file in all my virtual machines and enter that address to access my sites. Pretty tedious. Well, I recently found out that this can be avoided. In case there are others who didn’t know this and wasted their time editing hosts files, here’s how.

What you need to do is make sure your virtual machines use shared networking, find the IP address your Mac has in the VM’s virtual network, and use that address in the hosts file of the OS running in each virtual machine.

  1. Make sure your VM uses shared networking.
  2. The next step is to figure out what IP address your Mac has on the virtual machine’s network. The default seems to be 10.211.55.2, so you may want to skip to step 3 and try if that works first. If it doesn’t work you’ll need to figure out the correct IP address to use by doing the following:
    1. If you use Parallels Desktop 7 (or later I presume), open Parallels Desktop -> Preferences -> Advanced -> Network: Change Settings… and enable “Show in System Preferences” for Shared mode. Note that this option is not available in Parallels Desktop 6, but the default IP seems to be 10.211.55.2.
    2. Open System Preferences -> Network and check what IP address the Parallels NAT network service has.
  3. Open the hosts file in each of your Windows (or Linux, or whatever) guest machines and use that IP address for all your virtual host entries.
  4. Save the hosts file and open a web browser. You should now be able to access your local dev sites without having to edit any hosts files no matter what your Mac’s IP address is. (Though you’ll still need to add new entries when you set up a new virtual host.)

See also Access Mac OS10.6 Virtual Hosts Using Parallels 5.0 and Accessing Mac virtual hosts from a Parallels VM. That’s where I found most of this information.

Posted on September 10, 2012 in Productivity, Virtual Machines

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.