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?
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/
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.
To enable this on OSX I had to do the following:
- Shut your virtual machine down.
- Go to
VirtualBox Preferences -> Network -> Host-only Networks ->
click the "+" icon. Click OK. - Select your box and click the
"Settings" icon -> Network -> Adapter 2 ->
On the "Attached to:" dropdown, select "Host-only Adapter" and your network (vboxnet0
) should show up below by default. Click OK. - Once you start your box up again, you should be able to access localhost at
http://10.0.2.2/
You can refer to it by localhost
and access other localhosted sites by adding their references to the hosts file (C:\windows\system32\drivers\etc\hosts
) like the following:
10.0.2.2 localhost
10.0.2.2 subdomain.localhost