Reaching localhost from VMware / virtual machines on a Mac
I’m in the process of setting up a development environment on my mac. I’ve set up IE8 testing by converting Microsoft’s VPC images to a VMware compatible image. So the next thing I need to do is view my local webserver from VMware. Typing http://localhost doesn’t work because the virtual machine is an entity in itself so localhost is local to the virtual machine.
Having done a little of this in the past I knew the hosts file in folder c:\windows\system32\drivers\etc would need an entry, mapping my Mac’s IP address to a domain name. Sean Sperte reveals a secret VMware IP address that is particularly handy when you use a laptop because a laptop’s IP address is not likely to remain static. I’ll quote Sean here:
Type
ifconfig vmnet1into a Terminal window. You should get a return like this:vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet 192.168.115.1 netmask 0xffffff00 broadcast 192.168.115.255 ether 00:50:56:c0:00:01The “inet” number is your “secret” IP (in my case, 192.168.115.1).
Now that we have that number, we can edit the hosts file on the VM. We find it in:
C:/WINDOWS/system32/drivers/etc. Just open the host file with Notepad, and add each virtual host (domain) on it’s own line at the end of the document, like so:192.168.115.1 dev.triumphofgrace.com… and save. Afterwards refresh the VM’s DNS cache by typing
ipconfig /flushdnsin a command line window.
This worked perfectly for me.
Posted by Nick on January 11th, 2009 :: Filed under development,mac
Tags :: vmware
You can leave a response, or trackback from your own site.

June 24th, 2010
Thank you, works perfectly!
I applied a similar solution to Windows 7 host and Ubuntu 10.04 guest, with my local server set up on the guest. In Ubuntu, type ifconfig instead of ipconfig.
Cheers!
September 10th, 2010
Thanks very much for this simple solution! Works perfect for my Windows 7 install in VMware on 10.6.
September 14th, 2010
I’m trying this on XP running on VMWare on 10.6 but it isn’t happening.. I applied all steps without any problems but it doesn’t seem to work. Is there a known problem with XP or should it work as it does for 7?
This is what I’m doing in hosts (my inet is 192.168.232.1):
127.0.0.1 localhost
192.168.232.1 macserver
Assuming I can access it through http://macserver:8888/ but no luck. Does it have to be a domain name on the mac host? and if so, how do I set that up?
Thanks for your help as this is really bugging me not being able to test locally on IE.
Regards,
Rob.
November 25th, 2010
Veerrrrrrry helpful tip Rowlando, thanks for posting.
To Rob: have you set up a virtual host in Apache? Check this out:
http://shapeshed.com/journal/setting_up_local_websites_on_snow_leopard/
January 17th, 2011
Got it working in my mac. Thanks!
April 6th, 2011
[...] Reaching localhost from VMware / virtual machines on a Mac [...]
July 8th, 2011
[...] Reaching localhost from VMware / virtual machines on a Mac – Rowlando’s Blog [...]
July 15th, 2011
[...] VMware also works with my localhost, so i dont even have to copy the files around. This article explains how to do it, if you’re interested, here. [...]
July 27th, 2011
cant get this to work dont know what to type intp the browser window
August 1st, 2011
Hi. Thanks a lot, this works for me.
However. Is there any possible way to use localhost instead of xxxxxx/dev.triumphofgrace.com?
Im doing some WordPress designing were the absolut URL to the CSS files are in a DB like http://localhost/style.css and I’d therefor have to change the value everytime I’d want to check the website in IE.
September 11th, 2011
[...] Reaching localhost from VMWare / virtual machines on a Mac [...]
December 31st, 2011
[...] or what ever port into my emulated IE. So I did a bit of research and found this post from Rowlandos Blog wich I am simply going to paste here as a [...]