SSH port forwarding made easy

To forward a port on your local machine to that of a remote machine:
  $ ssh -f -N -L [local port]:[remote host]:[remote port] [forward host]

This forwards traffic destined for [local port] on the local host to [remote port] at [remote host] via [forward host].

For example, if you are behind a firewall that blocks the CVSup port (5999) you can circumvent the firewall with:
  $ ssh -f -N -L 5999:cvsup.at.freebsd.org:5999 tunnel.example.org

This forwards traffic destined for port 5999 on the localhost to port 5999 at cvsup.at.freebsd.org via tunnel.example.org

Another, probably more common example is when you want to tunnel your mail over an encrypted channel. For POP3 the tunnel command is:
  $ ssh -f -N -L 110:mail.somewhere.com:110 localhost

For IMAP replace 110 with 143.

The above tunnel assumes that you have an account on mail.somewhere.com and that port 110 is not blocked by your firewall.
|