I have a remote server(188.8.131.52) where I am running a python django webserver on port 8008. However, the remove server is only allowing ssh port 32686, which means that I cannot directly access remote server at port 8008 to view the webserver. This is why I am local port forwarding through ssh so that I can access remote server port 8008 from my local host port 8355(some random port number).
Looking up the guides on google, I came up with the following ssh command for my local port forwarding setup.
ssh -L 8008:184.108.40.206:8355 firstname.lastname@example.org -p 32686
while ssh login worked, I cannot access the webserver from local host through port 8355. Instead, the console showed the following error.
channel 3: open failed: connect failed: Connection refused
Fixed ssh command
After some more googling and internal reflection, I cam up with the correct ssh command.
ssh -L 8008:127.0.0.1:8355 email@example.com -p 32686
When I ssh login using this command, I can now access the webserver in remote host through accessing local host port 8355.
The only difference is the remote host ip address format inside local port option definition. I think if we use the public ip of the remote host(220.127.116.11), then it will forward packets from local host to the “outside” of remote host’s port 8008 which is, as I mentioned earlier unavailable. By changing the public remote host ip address to “127.0.0.1”, I believe it is notifying remote host’s sshd that the incoming packets do not need to be redirected to the “outside” of port 8008 but rather process it internally and redirect it to the “inside” of port 8008 right away. This way it will not be blocked by the firewall.