SSH port forwarding not working in macos catalina (10.15)
Solution 1:
From What's ssh port forwarding and what's the difference between ssh local and remote port forwarding:
I have drawn some sketches ssh tunnel starting from local
ssh tunnel starting from remote
Introduction
local:
-L Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
ssh -L sourcePort:forwardToHost:onPort connectToHost
means: connect with ssh toconnectToHost
, and forward all connection attempts to the localsourcePort
to portonPort
on the machine calledforwardToHost
, which can be reached from theconnectToHost
machine.remote:
-R Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.
ssh -R sourcePort:forwardToHost:onPort connectToHost
means: connect with ssh toconnectToHost
, and forward all connection attempts to the remotesourcePort
to portonPort
on the machine calledforwardToHost
, which can be reached from your local machine.Examples
Example for 1
ssh -L 8080:localhost:80 SUPERSERVER You specify that a connection made to the local port 80 is to be forwarded to port 8080 on
SUPERSERVER. That means if someone connects to your computer with a webbrowser, he gets the response of the webserver running on SUPERSERVER. You, on your local machine, have no webserver running.
Example for 2
ssh -R 80:localhost:8080 tinyserver You specify, that a connection made to the port 80 of tinyserver is to be forwarded to port 8080 on
your local machine. That means if someone connects to the small and slow server with a webbrowser, he gets the response of the webserver running on your local machine. The tinyserver, which has not enough diskspace for the big website, has no webserver running. But people connecting to tinyserver think so.
More examples
Other things could be: The powerful machine has five webservers running on five different ports. If a user connects to one of the five tinyservers at port 80 with his webbrowser, the request is redirected to the corresponding webserver running on the powerful machine. That would be
ssh -R 80:localhost:30180 tinyserver1 ssh -R 80:localhost:30280 tinyserver2 etc.
Or maybe your machine is only the connection between the powerful and the small servers. Then it would be (for one of the tinyservers that play to have their own webservers):
ssh -R 80:SUPERSERVER:30180 tinyserver1 ssh -R 80:SUPERSERVER:30280 tinyserver2 etc