← ../

Local port forwarding:

ssh -NL 2525:localhost:25 user@remoteserver

breaking this down :

you can now access the port 25 on the remote machine via your local ip (localhost) on port 2525

telnet localhost 2525



Dynamic port forwarding:

ssh -ND 8080 user@remoteserver

this will listent to local port 8080 and create a SOCKS proxy

breaking this down :

you can now use remoteserver as an exit node if your use sock5 proxy in your browser or other application (127.0.0.1:8080)

Remote port forwarding:

ssh -NR 2525:localhost:25 user@remoteserver

breaking this down :

the remote machine can now access port 25 on the local machine via its ip (localhost) on port 2525

telnet localhost 2525



Tunnel through a host:

ssh -NL 5432:database:5432 -N webserver

breaking this down :

you can now access the database server (port 5432) via your local ip (localhost) on port 5432 (all of this via the webserver)

psql localhost



Bind a port on host2 via host1:

ssh -NL 9999:localhost:9999 host1 ssh -NL 9999:localhost:1234 -N host2

breaking this down :

you can now access the whatever service runs on host2 (port 1234) via your local ip (localhost) on port 9999 (all of this via the host1)

nc localhost 9999