0
Machines:
Host laptop: 192.168.0.5
VirtualBox VM with NAT Network Adapter: 192.168.56.101

If I run this it doesn't work if I open in the browser 192.168.0.5:30012:

ssh -L 30012:192.168.0.5:8080 -N -f -l usersu 192.168.56.101

But this works perfectly fine:

ssh -L 30012:127.0.0.1:8080 -N -f -l usersu 192.168.56.101

I also added the rule in UFW to allow 30012. What am I doing wrong?

I need to do this port forwarding from VirtualBox VM in which I do web site development. I wanted to check the web site using mobile device.

The VirtualBox VM has two network interfaces NAT and host only. For some reason Virtual Box NAT port forwarding stopped to work (Host and guest restart did not help). I decided to use SSH port forwarding. But it only works on 127.0.0.1.

I know I could add 3rd network inteface "Bridged Adapter" in VirtualBox to get a new IP in local network but this solution I don't like because it introduces some complexity.

192.168.56.101 is the host only network interface of VirtualBox VM. I can access it only from host and guest VMs, but not from mobile phone which is connected to the local network which is 192.168.0.x.

Tried to use this

ssh -L 30012:0.0.0.0:8080 -N -f -l usersu 192.168.56.101

It works for 127.0.0.1, but doesn't work for 192.168.0.5.

Based on the @JakeGould’s comment at the moment I use workaround in which I added 3rd Bridged Network interface and for webpack did this change as explained in this answer.

  • You normally cannot communicate with your local intranet address on the localhost. Why exactly are you against using localhost (127.0.0.1)? The formatting of your question makes your question hard to read. You should edit your question to clearly indicate which command is working. – Ramhound Apr 25 at 0:27
  • 1
    Most likely your application is set to only bind to localhost (127.0.0.1) when if you want the application to network off of your device you need to bind to 0.0.0.0 or even 192.168.56.101. The 0.0.0.0 would bind your application to any port on your machine where 192.168.56.101 would only bind to that specific IP address. – JakeGould Apr 25 at 0:30
  • @JakeGould - Any port or any address? Wouldn’t 0.0.0.0 be my address on a given port? (Whatever port SSH is set to) – Ramhound Apr 25 at 0:51
  • @Ramhound Binding a server to 0.0.0.0 tells most applications: “Use any network interface on this machine and bind the application to that interface.” But when the user says they want to connect their app to the LAN, this idea might not work since LAN access would imply the host would need to be accessible on the LAN. This advice I posted would work for the guest. The real solution is to use “Bridged Mode” and allow the VM to be a part of the LAN despite the claims of “complexity” raised by the original poster. Bridged mode is the only real solution here. – JakeGould Apr 25 at 0:59
  • @user1325696 Did my comments solve your issue? – JakeGould Apr 25 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.