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?
You most likely have your virtual machine’s networking set to NAT. If you set your networking to Bridged you should be able to access your host machine by its hostname. For example, if your hostname is “jsmith-Precision-7510” and you want to open http://localhost:3000/, you will be able to view that page at http://jsmith-Precision-7510:3000/.
To find your hostname, open a terminal/console and then run the command
hostname
. Your hostname will be outputted on the next line.See the VirtualBox documentation for instructions on how to set your networking setttings to Bridged.
If you have adapter attached to NAT, nowadays it's better and more elegant solution to set port forwarding to local ports.
Settings
>Network
>Adapter
>Advanced
>Port forwarding
Just insert new rule and set
Host port
andGuest port
to80
(for http) or22
(for ssh), and so on.Then you can access that machine by entering just
http://localhost
You may also want to switch NAT to transparent mode.
If you use Virtual Box you can connect Mac OSX (and I think Linux) to your virtual windows machine using one line of code --> I suggest stopping the box before running this in terminal.
VBoxManage modifyvm "YOUR VM NAME" --natdnshostresolver1 on
I will note that this is from the Dinghy docs, which I am running, but its a virtual box command so it shouldn't actually care what you use as long as its Virtual Box
Not being able to re-direct requests to localhost in the VM to the host's localhost is now baked in to Windows (https://tools.ietf.org/html/rfc6761#section-6.3), including the VM's available at https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
For security reassons Microsoft now prevents host file entries for overriding the address of localhost to anything other than the loopback address ::1. So adding a line the VM's host file such as
will be ignored.
There are two ways (that I know of) to override this:
1) use NETSH to portproxy to the host
(where 10.0.2.2 is the default gateway on the VM and 8000 is the port you want to resolve to on the host.)
2) Setup IIS to perform Application Request Routing and then rewrite requests for localhost:port to the hostIP:port
https://docs.microsoft.com/en-us/iis/extensions/configuring-application-request-routing-arr/creating-a-forward-proxy-using-application-request-routing
A combination of a few things eventually got things working on my end. Running a flask server on macosx.
In my windows VM I edited the hosts file:
C:\windows\system32\drivers\etc\hosts
10.0.2.2 outer
Shutdown VM and on my Mac in VirtualBox:
VirtualBox > preferences > Network > Host-only Networks > +
to add a networkvboxnet1
My_VM > settings > Network > Adapter 1
.Enable Network Adapter
and setAttached to:
toBridged Adapter
.Advanced > Promiscuous Mode:
toAllow VMs
.OK
My_VM > settings > Network > Adapter 1
.Attached to:
back toNAT
.Then I went to
Adapter 2
Attached to:
toHost-only Adapter
and select the previous added networkvboxnet1
.I started my server on my mac, running on
127.0.0.1:5000
and this was now accessible on my vm athttp://10.0.2.2:5000
Man what a nightmare to test on IE on mac. How is there not a simpler way?
I had to go into virtualbox and change my network settings to 'NAT'. After that, I was able to hit
localhost
running on my host machine from my emulator on virtualbox throughhttp://10.0.2.2:3000