Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Localhost hosted on one virtual machine by another virtual machine

Background:

On my Windows 7 machine I have a web development virtual machine running Ubuntu. The VM's network structure is set to NAT (as opposed to bridge, etc.). I run additional virtual machines of XP with different IE browsers on them for testing.

My Question:

I know that when using NAT on a virtual machine, you are able to access the web server from the host inside of a virtual machine by directing a web browser to 10.0.2.2. If http://localhost is hosted on Virtual Machine A (Ubuntu). How do I access that from Virtual Machine B (any XP VM)?

Edit:

I am looking for an elegant solution, similar to that of using 10.0.2.2 as described above. I would prefer not to have to specify dynamic IP's for the VM's as well as not having to look up the VM's IP every time I want to access it. Is anything like this possible?

like image 262
ServAce85 Avatar asked Jun 26 '11 08:06

ServAce85


People also ask

How do I connect two VMs on different hosts?

You just need to forward the ports that you want (which you can do in VirtualBox's network settings), then connect to the IP of one host from the other host's VM. As @TJJ said, your other option is to used bridged networking instead of NAT, which would let the computers connect with no extra configuration.

Can someone else connect to your localhost?

localhost is a special hostname that almost always resolves to 127.0. 0.1. If you ask someone else to connect to http://localhost they'll be connecting to their computer instead or yours. To share your web server with someone else you'll need to find your IP address or your hostname and provide that to them instead.


1 Answers

Just put the IP address of VM A instead of localhost in the browser of VM B.

This assumes theres no firewall rules preventing it from being accessed.

Its worth doing a ping test from VM B first to eliminate any other issues first.

like image 106
markbarton Avatar answered Sep 27 '22 00:09

markbarton