Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Addressing localhost from a VirtualBox virtual machine [closed]

I have a local test/development server (HTTP, of course), listening to port 8000.

I'm working on Linux, so to test the page on Internet Explorer 6, 7, 8, etc. I run a virtual machine using VirtualBox; I also need to see how it look on Firefox in a windows environment (fonts for instance are different).

In my real machine, I open the website simply using the URL http://localhost:8000, how do I address this localhost from the virtual machine?

Right now my workaround is to use the IP address. Any better ideas?

like image 368
hasen Avatar asked Aug 11 '09 17:08

hasen


People also ask

How do I access my localhost virtual machine?

a) put your VM in bridge network configuration. You should then be able to connect to the VM via its IP address. Be careful to not use https:// instead of http:// as in that case you have to be able to serve a correct certificate for that IP address!

How do I access VirtualBox internal IP from host machine?

You can edit settings of this VirtualBox network by going to File > Host Network Manager. In our case, the default network address of the host-only network is 192.168. 56.0/24 and the IP address of the virtual network adapter on the host machine is 192.168. 56.1.


2 Answers

Googling turned this up: http://data.agaric.com/localhost-from-virtualbox-xp-install-ubuntu

It suggests using IP: http://10.0.2.2, and it worked for me.

So, I edited the hosts file, C:\windows\system32\drivers\etc\hosts, and added this entry:

10.0.2.2   outer 

If you're testing on IE8, remember to put http:// in the address bar. Just putting the ip directly will not work.

For example:

http://10.0.2.2:3000/ 
like image 62
hasen Avatar answered Sep 28 '22 04:09

hasen


macOS

I'm running Virtual Box on macOS (previously OS X), using Virtual Box to test IE on Windows, etc.

Go to IE in Virtual Box and access localhost via http://10.0.2.2 for localhost, or http://10.0.2.2:3000 for localhost:3000.

I kept Network settings as NAT, no need for bridge as suggested above in my case. There is no need to edit any config files.

like image 38
Jonathan Lin Avatar answered Sep 28 '22 04:09

Jonathan Lin