1

I have a ColdFusion server that launches on 127.0.0.1:WXYZ within a virtual machine on VirtualBox. I need to be able to access the server from my Host OS. I have tried using a Bridged adapter as well as NAT with Port Forwarding, however, I have not managed.

I have also tried using normal NAT with port forwarding, whilst also using netsh interface portproxy to relay requests to attempt to expose the guest's internal 127.0.0.1.

Both the guest and the hosts are Windows 10. Changing the address that the server binds to is not an option in this scenario. I am not certain that I have attempted all the steps that I have mentioned in the ideal way, thus if you have any suggestions about anything that I have tried, or about anything I could try, please let me know.

2
  • 1
    By design, localhost is not reachable from outside the host. Is using additional tools (namely socat) acceptable?
    – Daniel B
    Sep 23, 2021 at 11:31
  • Yes. I used netsh to try to replicate socat functionality Sep 23, 2021 at 11:44

2 Answers 2

1

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:

Port forwarding

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:

Network setup

0

The question suggests that you're trying to access the guest from the host using IP address 127.0.0.1. This cannot work, 127-addresses refer only to localhost. I.e. from the point of both computer systems, host and guest, 127.0.0.1 = "myself".

You need to use the actual interface IPs. For example I have a VB VM running with a bridged adapter. My Wi-Fi provides it IP address 192.168.43.177. My host connects to the same Wi-Fi, with IP address 192.168.43.28. If I want to access Webmin:s interface from within the VM, I can open the browser to https://127.0.0.1:10000, but if I want to access it from the host I have to open it to 192.168.43.177:10000.

This works the same way whether the interface is bridged or NATted.

10
  • To make it clear, I don't require the IP address to be 127.0.0.1 when trying to connect from the Host OS. I just want to be able to access the 127.0.0.1 that is hosted in the guest...FROM the Host. Sep 23, 2021 at 11:52
  • You simply use the actual IP address of the guest OS. In my example for my VM both 127.0.0.1 and 192.168.43.177 mean "myself". You'll find the guest's accessible IP address with command ipconfig if it's Windows; or ifconfig or ip addr on Linux. You need to run the command on the guest OS. Sep 23, 2021 at 11:58
  • [When in NAT mode] Using ipconfig, I am told that my Guest OS has IP 10.0.2.15. The port that the server is running on is 62094, thus I am pinging 10.0.2.15:62094 from my host OS. This results in an error. Pinging the same address from my Guest OS also does not work. The only way I have been able to access this server is by accessing 127.0.0.1:62094 from the Guest OS. Sep 23, 2021 at 12:21
  • You can't ping a port, that's not how ping works; only the IP address. Trying to ping a port always returns an error. You can ping 10.0.2.15 and if it responds, try telnet 10.0.2.15 62094. If the port's working you will get Connected to 10.0.2.15 and possibly escape character. You can then break the connection with Ctrl+C and try to access the server with 10.0.2.15:62094. Sep 23, 2021 at 12:29
  • curl, I meant to say curl not ping. Sep 23, 2021 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .