Guests can connect to hosts, and hosts to guest, but not out of the box.
Here is a scenario.
Suppose you have a host, and two guests (in my case, Windows host (HOST), and a Linux (GUEST1) and Windows (GUEST2) virtual image):
Suppose further more, you run a website on one guest (in my case, http://localhost:8081, on the Windows GUEST2).
I run both guests in NAT networking mode.
HOST -> GUEST2 : Use NAT port forwarding rule, on 8081. Go to networking of the virtual guest (GUEST2), and add the rule there. So, now on the host, http://localhost:8081 will reach the GUEST2 website.
GUEST1 (linux) -> HOST(W10) -> GUEST2(W10) website on port 8081
Go to your other GUEST1, in my case, Linx, run netstat -rn:
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 **10.0.2.2** 0.0.0.0 UG 0 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 enp0s3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
Now, your website can be reached on the gateway, http://10.0.2.2:8081.
That will trigger the port NAT from HOST to GUEST2 again.
1Note: If you have name-based virtual hosts configured in apache on your host machine, then you can access them by simply creating a mapping in the guest's machines hosts file for
10.0.2.2 yourvirtualhostname.local (or whatever)
– User – 2014-08-22T01:12:59.307@User are you sure that your last comment will work? I have a virtual host on my VB host set to
http://example.dev
, and mapping10.0.2.2
to anything on my VB guest doesn't help access it at all. – Томица Кораћ – 2015-01-06T11:36:36.0301
@ТомицаКораћ it does work. For example see: http://askubuntu.com/questions/36183/how-to-access-apache2-virtual-host-from-virtualbox-or-any-vm however, you probably should open a separate question to get this solved.
– User – 2015-01-06T17:11:24.917@User you're right. I think I had to restart my guest machine, but now it's working. Thanks. – Томица Кораћ – 2015-01-06T19:21:06.730
Doing that, I get an 401 http code when fetching the page. I have disabled the host firewall, but no luck... I only get to see my favicon on the browser's tab... – user2173353 – 2015-10-14T12:14:39.397
1"Enable ONE network adapter" means under the network settings of your virtual machine (within VirtualBox) enable only one of the adapters. Got me a bit confused when I first read it. – Marquez – 2015-12-16T19:37:56.323
Does this only work for web servers? I can get this working with one and see a hello world page from the host, but when I write my own little Python server listening on 21333 instead of 8080 the connection always times out. – Joseph Garvin – 2018-12-08T21:32:51.717
Note: You can change the guest's network settings while it is running via Machine > Settings > Network (at least in version 6.0). – trebormf – 2019-02-13T16:06:14.540
Thanks for sharing this information. It really saved my day and lot of reading around networking when using virtualbox. – h3xh4wk – 2019-11-14T08:36:11.423
1"Enable ONE network adapter". Where is this done? – jshen – 2014-05-08T16:39:48.203