Addressing localhost from a VirtualBox virtual machine
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.
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/
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