Recently I’ve included into my suite of software VMWare Fusion. I was previously using the open source Virtual Box and a copy of Windows XP to emulate IE7 inside of my mac. I’m a web developer so IE counts wether I like it or not.
Even though I had these tools I realized to hitting into localhost was not as easy as just typing localhost:9000 or what ever port into my emulated IE. So I did a bit of research and found this post from Rowlandos Blog which I am simply going to paste here as a reference
ifconfig vmnet1 into a Terminal window. You should get a return like this:
mtu 1500 inet 192.168.115.1 netmask 0xffffff00 broadcast
192.168.115.255 ether 00:50:56:c0:00:01
The “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:
… and save. Afterwards refresh the VM’s DNS cache by typing
ipconfig /flushdns in a command line window.
Boom, you can now point to your macs localhost from your emulator and test all that you need to test in Windows.
Best of luck!
4 thoughts on “vmware and localhost”
This works fine but you do not have to rely on NAT (using the 192.x.x.x address range) but you can actually bridge your main OS (OSX in this case). Do some Google searches on bridging via VirtualBox and you will get some good information. The advantages are that you can actually access the VM from outside your actual computer running the hypervisor. I have been running Linux as my main OS at work for years and used multiple hypervisors for my Window VM (KVM (currently), VirtualBox, and VMware).
Awesome info Sascha! If you have any cool links already please share.
I will just refer you to the VirtualBox documentation in this case. Not sure how VMware Fusion will implement this.
Also, just an FYI from a security perspective. If you bridge your VM’s interfaces, it will be accessible from your network and even possibly from the Internet, depending on your IP address space and router/firewall setup. Therefore, if you are developing and testing confidential applications, it might be a good idea to keep them off your network.