Accessing Mac virtual hosts from a Parallels VM

I finally moved to an Intel machine. Despite the dramatic speed improvement in everything Java-related, namely Eclipse, there’s another big advantage: being able to run IE on Windows using a virtual machine. Unfortunately, that’s something every web developer must do to ensure his or her application will work on the most used (and crappy) browser on earth.

I installed Parallels and created two virtual machines, one for IE 6 and another one for IE 7. This way I’m sure there are no weird problems between those two versions (having more than an IE version on Windows can only be accomplished by hacks, and hacks are bad). Also I can install Visual Web Developer Express Edition on each of the VMs, and use either IE 6 or 7 to debug.

My apps run inside virtual hosts on Mac OS X apache, under a fake DNS name. On Mac OS X it’s easy to add the DNS entry to the /etc/hosts file, under the entry. This way, your DNS name will always point to your mac, and you’ll be able to reach your virtual host.

I wanted to do the same from inside Windows running on Parallels. An easy way would be to edit the Windows hosts file, adding the Mac OS X public IP to the file. But that will only work if the OS X IP doesn’t change. My Intel mac is an MBP, and I change the network I use often, so I needed a little more flexibility. So, this is the way I found to do this:

  1. Configure your VM to use Shared Networking. This wall, Parallels extensions installed on your Mac will create a NAT network where your virtual machine will be hooked into.
    Paralleles Configuration Screen
  2. Open Mac System Preferences, and look for the “Parallels NAT” network port. This is an interesting one, because it allows the Mac itself to be connected to the virtual NAT network, using an IP on the NAT subnet. Write down that IP: this will be the IP you’ll use to access the Mac virtual hosts from within the virtual machines.
    System Preferences
  3. Finally, edit Windows hosts file. This file is located on \WINDOWS\system32\drivers\etc\hosts. Add a line with the IP (in my case, and the name of the virtual host, just like you do on the Mac.
    Windows hosts file

That’s it. Now you can access your Mac virtual hosts from Windows, whatever the Mac IP is. Ick, what’s a Windows screenshot doing in my blog!?

20 thoughts on “Accessing Mac virtual hosts from a Parallels VM”

  1. Just wanted to thank you for this – googled for this info and came across this page. It’s easy to follow and is well explained, and it worked! So thanks – you saved my ass!

  2. Thank you for posting this information! I am developing using mac host and vmWare running IEs and this advice is also relevant to me. Also, came here via google!

  3. Huh. Interesting. I have a site on my mac in /Library/WebServer/Documents/, and one in /Users/Shared/. The one in /Users/Shared/ is configured with a named Virtual Host in my apache config. On my mac, I type, and it takes me to that site. To reach the one in /Library/WebServer/Documents/, I just hit localhost. When I try your trick, from Parallels resolves to the localhost site, not my site. I’m puzzling over why this is.

  4. Unfortunately, with Parallels 4.0 and Snow Leopard, somehow on shared network my Parallels NAT adapter no longer appears in the System Preferences and despite my sincerest efforts I was unable to do anything. Instead, I used bridging but it is quite nasty because I have to use 2 IP’s from the network instead of passing through the Mac’s IP…any similar issues?

    1. I still did not upgrade to Snow Leopard (as I’m waiting for PGP). Anyway, I had experienced issues when installing the OS X upgrades (ie, like from 10.5.6 to 10.5.7) with Parallels 3. The network ports were still there, but they didn’t work at all unless I reinstalled Parallels after the upgrade. I think I don’t have that issue since I upgraded to Parallels 4.0, but it may be something similar to what I’ve experienced. Have you tried to re-install Parallels?

  5. Great tutorial, super simple to follow and was able to get working in a jiff.

    Additionally, I was wondering if anyone knows how to get this to work with virtual hosts. Bear with me as I try to explain using my half-baked knowledge of Apache/Networking.

    The above works fine for anything I might have at “http://localhost/” but I usually have two to three projects hosted on my Mac and I like to use virtual host aliases (?terminology?) that I can access at something like “http://project1/” & “http://project2/” — is there way to access these virutalhosts using this same trick?

      1. It didn’t work for me, sure I’m doing something wrong.
        first of all, bridge between Parallels and mac works great (thank’s for that!) because all the sites under MAMP htdocs (mounted in port 8888) renders ok.

        but, accessing to a virtualhost don’t…

        My VirtualHost
        NameVirtualHost myproject.local:8888

        DocumentRoot “/Developer/projects/myproject”
        DirectoryIndex index.php

        AllowOverride All
        Allow from all

        And my host in VM Windows: myproject.local

        If I enter “http://myproject.local:8888/” takes me to the htdocs from MAMP, not to the VH…
        Any ideas?

        1. Sorry but the post stripped out the tags from the VH, let’s try again..

          NameVirtualHost gdp.local:8888

          DocumentRoot “/Developer/projects/GDP”
          DirectoryIndex index.php

          AllowOverride All
          Allow from all

  6. I’ve upgraded to 6.0 and now I’m unable to connect to virtual hosts. The settings have disappeared. Anyone have any ideas/luck with 6.0 and virtual hosts?

    – MacBook Pro running Parallels 6.0 virutualizing Windows 7

Leave a Reply

Your email address will not be published. Required fields are marked *