I have solved this myself in 3 steps. I'm going to post the answer in case this happens to anyone else. For this example, I have connected the Host OS' localhost:3000
to the server that is running on localhost:62094
on my Guest OS.
Step 0 - THE MOST IMPORTANT STEP
Make sure that your Guest OS has File Sharing or Network Discovery turned on. This is why I was not able to access the Guest OS when @Peregrino69 mentioned it in the comments of another answer. Enabling this setting allowed me to ping the IP of the Guest OS (not the localhost however, that required the remainder of the steps I took in this answer).
1. Find the Guest OS IP
This was done by running ipconfig
and reading the IPv4 Address
field. In my case it was the default value of 10.0.2.15
.
2. Port Forward from the VirtualBox settings.
The second step is to port forward calls from the host's localhost
to the guest by connecting 127.0.0.1:3000
to 10.0.2.15:3000
in the VM's network settings. This will relay calls made to localhost:3000
in the Host OS to 10.0.2.15:3000
in the Guest OS. Screenshot of settings:
3. Relay Calls to 10.0.2.15 to Guest's localhost
This was done by using the netsh
command. The following exact command was used:
netsh interface portproxy add v4tov4 listenaddress=10.0.2.15 listenport=3000 connectaddress=127.0.0.1 connectport=62094
This will relay calls made to 10.0.2.15:3000
to localhost:62094
within the Guest OS.
Result
This results in accessing localhost:3000
from the Host OS incurring a response from 10.0.2.15:60294
in the Guest OS, where my server is hosted. I have attached a diagram of my final network setup, in case the steps were not clear enough:
localhost
is not reachable from outside the host. Is using additional tools (namely socat) acceptable?