Local And Remote Forwarding
There are two kinds of port forwarding: local and remote
forwarding. They are also called outgoing and incoming tunnels,
respectively.
Local port forwarding forwards traffic coming to a local port
to a specified remote port. For example, all traffic coming to
port 1234 on the client could be forwarded to port 23 on the
server (host).
Note: The value of localhost is resolved
after the Secure Shell connection has been established - so
when defining local forwarding (outgoing tunnels),
localhost refers to the server (remote host computer)
you have connected to.
Remote port forwarding does the opposite: it forwards
traffic coming to a remote port to a specified local port. For
example, all traffic coming to port 1234 on the server (host)
could be forwarded to port 23 on the client (localhost).
It is important to realize that if you have three hosts, client,
sshdserver, and appserver, and you forward the traffic coming to the
client's port x to the appserver's port y, only the
connection between the client and sshdserver will be secured. See
Figure Forwarding to a third host.
Figure :
Forwarding to a third host.