Last Updated: February 25, 2016
·
548
· skeep

Open localhost from VM

For cross browser development we generally need to test application in different OS. To test web app from a Windows VM in Mac follow below steps:

  • Open Terminal and type

ifconfig vmnet1

It should give you something similar as below:

vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 00:50:56:c0:00:01 
    inet 172.16.55.1 netmask 0xffffff00 broadcast 172.16.55.255

what we are interested in is
inet 172.16.55.1

take a note of this ip address.

  • Now switch to Windows VM. Open the below mentioned file
C:\Windows\System32\drivers\etc\hosts

note hosts is the name of the file and do not have an extension.

  • Add below line at the end of the file
172.16.55.1 localhost
  • Now we have flush our DNS to make this work Open command prompt in windows and type
ipconfig /flushdns

Thats it. Open your browser and http://localhost/ should work. Optionally you may need to add a port if your app is running on a port. The port number should be same as in Host system