On the use of SSH portforwarding, there are already a lot of good articles on the web, I just draw two diagrams here to explain.
The first thing to remember is:
SSH port forwarding naturally requires an SSH connection, while the SSH connection is directional, from the SSH Client to the SSH Server.
The application we want to access is also directional, and the direction of application connection is also connected to the server side of the application from the client side of the application. For example, when we want to access a Web site on the Internet, the direction of HTTP applications is from our own host (Client) to the webserver in the distance.
If the connection between the SSH connection and the application is in the same direction, we will say that it is local forwarding.
Ssh-l <local port>:<remote host>:<remote port> <ssh
If the connection between the SSH connection and the application is different in the direction of the connection, we will say that it is a remote forwarding.
Ssh-r <local port>:<remote host>:<remote port> <ssh
Local forwarding listens to a port on the local machine, and all data accessing the port is transmitted through the SSH tunnel to the remote corresponding port, as the following example.
Local port forwarding binds to the Lookback interface, which means that only localhost or 127.0.0.1 can use native port forwarding, and other machine-initiated connections will only get "connection refused." To allow other machines to share this tunnel for forwarding, you need to use the Gatewayports keyword in the configuration file, or use the "-g" argument directly under the command line.
In addition, the <remote host> and <ssh hostname> in the local forwarding command can be different hosts.
Remote forwarding is the opposite of local forwarding, when the SSH tunnel is opened, the remote server listens on a port, and all access to the remote server specified port is routed through the tunnel to the local corresponding port, as the following example shows.
Here is a good article to introduce SSH portforwarding http://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/
SSH-GFNL 5924:19.2.192.209:5924 aaa@192.168.24.41