131

I've just created a new Windows XP VM on my Mac using VMware Fusion. The VM is using NAT to share the host's internet connection.

How do I access a Rails application, which is accessible on the Mac itself using http://localhost:3000?

Cœur
  • 37,241
  • 25
  • 195
  • 267
John Topley
  • 113,588
  • 46
  • 195
  • 237

7 Answers7

139

On the XP machine, find your IP address by going to the command prompt and typing ipconfig. Try replacing the last number with 1 or 2. For example, if your IP address is 192.168.78.128, use http://192.168.78.1:3000.

nbro
  • 15,395
  • 32
  • 113
  • 196
JW.
  • 50,691
  • 36
  • 115
  • 143
  • I am using Lion as Host and Win7 as Guest, but I could not visit my rails app on my mac using this. Why? – larryzhao Dec 30 '11 at 08:10
  • 3
    if your local network ip address is: 192.168.1.122 then you should use http://192.168.1.122:3000 and that should work – dbslone Jul 18 '12 at 16:05
  • 6
    Important Note: These solutions are not working if you are connected using VPN. – Harshay Buradkar Mar 09 '13 at 00:09
  • 1
    The answer no longer works in VMware Fusion 11. VM IP = 172.16.204.128, gateway = 172.16.204.2 and neither 172.16.204.1 nor 172.16.204.2 is reachable. The host LAN IP as suggested by @dbslone worked. – Dima Korobskiy Sep 04 '20 at 22:08
81

You can use your host Mac's (or any other Mac on the network) 'local' name:

http://macname.local:3000/

where macname is the network name of your host (or other desired) Mac.

Michael Larocque
  • 1,166
  • 1
  • 6
  • 6
  • 2
    Superb. I didn't know about the .local bit. Thanks! – wentbackward Jun 01 '09 at 17:24
  • is this only available if the VM was configured on that mac? I ported another VM from somewhere else and computername.local is not working for me – spankmaster79 Dec 13 '10 at 13:19
  • 8
    the ".local" is a mac-only thing. When you open up System Preferences / Sharing, it actually shows you the computer name, and below it notes that to access it on the local network you should use computername.local - this applies for connection to file sharing, web sharing, etc – Johnus Dec 24 '10 at 00:57
  • 1
    This seems to require that the VMWare network is configured to be NATted (or, presumably, bridged); the 'host only' configuration results in the network connection timing out. It's not clear to me why this should be the case, but... – Norman Gray Feb 04 '11 at 12:15
  • I used to use this method and it worked great! But recently it stopped working, and I'm not sure why. Maybe it stopped with an update to Snow Leopard or maybe it stopped with an update to Fusion. Now my machostname.local resolves to a public address out on the internet. – Jason Mar 24 '11 at 16:46
  • This worked like charm. Had totally forgot about this – Amir Rustamzadeh Jul 11 '11 at 02:56
  • perfect. I never knew about this. Just saved a whole lot of fluffing about. – Aaron Moodie Sep 12 '11 at 13:08
  • This stopped working for me after upgrading to Fusion 7. I have to use the method offered by JW above with http://#.#.#.1:3000 – JCC Jan 13 '15 at 19:49
14

For future visitors: once you've got the IP address figured out, you can add an entry to the Windows hosts file, which is located at C:\Windows\system32\drivers\etc\hosts, to map the IP address to a (virtual) server name. Add a line like this:

192.168.78.1   myrubyapp

Now you can access the site in IE at the address http://myrubyapp:3000

If you use virtual hosts under Apache you'll need this to provide the correct server name.

J. Perkins
  • 4,156
  • 2
  • 34
  • 48
10
  1. On the XP machine, Start -> Connect To -> Show all connections.
  2. Double click Local Area Connection.
  3. Click the Support tab.
  4. Take the Default Gateway IP <gateway-ip> and hit http://<gateway-ip>:3000 in your browser.

Gotcha: You must have http:// in the address or IE will give you "The webpage cannot be displayed".

Richard Poirier
  • 4,878
  • 5
  • 26
  • 21
10

As this question is quite old and referring to XP, here is an alternative for new OSs;


If you're rocking Vista or Windows 7 as the Guest OS, and you have Virtual Hosts setup in the Host via Apache, here's how to setup:

In the Host OS, you need to ensure the network connection is done via NAT;

  1. Right click the network icon in the VM window (bottom-right)
  2. Select "NAT"
  3. Select "Connect"
  4. Wait for the guest OS reconnect to the network

Then, In the Guest OS;

  1. Click Start > Network > Network & Sharing Center
  2. Click "View Status" next to the network connection
  3. Click "Details"
  4. Find "IPv4 Default Gateway"
  5. Open Wordpad
  6. Edit C:\Windows\System32\drivers\etc\hosts
  7. Add a line to the file such as:

    [default-gateway-IP] www.example.com
    [default-gateway-IP] example.com
    
  8. Save

  9. Try opening http://www.example.com or http://example.com in IE

Jess Telford
  • 12,880
  • 8
  • 42
  • 51
  • It's very weird but I had to substract 1 from the gateway ip. Actually it worked for me to find out by pinging the host: `ping .local` and putting that ip in the hosts file – Cristian Nov 07 '12 at 15:49
  • 1
    In place of steps 1-4 in the Guest OS, you can also open the Run Dialogue, type `cmd` + , then type: `ipconfig /all` + , and find the "Default Gateway" there. – Jess Telford Mar 11 '13 at 02:58
  • Thank you Jess!. `ipconfig /all` was faster too – Emerson Rocha Jul 29 '13 at 04:30
6

For Django it's important to do the following:

./manage.py runserver [default-gateway-IP]:8000

because

https://docs.djangoproject.com/en/dev/ref/django-admin/

Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).

Googol
  • 2,815
  • 2
  • 22
  • 13
5

I just spent an hour trying to get this to work following the steps on SO but mine ended up being a bit different.

VMWare settings

1.) Set VMWare connection to NAT
2.) run > cmd > ipconfig > copy Default Gateway value
3.) edit hosts file (c:/Windows/System32/drivers/etc/hosts)

  • add this to your hosts file:

<gateway-ip> yourserver.local

OS X settings

1.) edit Apache config (e.g., sudo vim /etc/apache2/httpd.conf)

  • add this vhost entry to your httpd.conf file:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
    DocumentRoot "/path/to/your/project"
    ServerName yourserver.local

    <Directory "/path/to/your/project">
        AllowOverride All
        Options All
    </Directory>
</VirtualHost>
  • save & quit (:wq)

2.) Edit your hosts file (sudo vim /etc/hosts)

  • add this line to your hosts file

127.0.0.1 yourserver.local

3.) Restart Apache (sudo apachectl restart)

I found that I had to switch the connection setting on VMWare in order to restart the connection before these settings worked for me. I hope this helps.

Dennis Plucinik
  • 224
  • 3
  • 8