theCAT
  
Report a Problem:
Email: support@cat.pdx.edu
Phone: 503-725-5420
Location: FAB 82-01
  USERS PLATFORMS SYSTEM RESOURCES    
Home Students Fac/Staff CS Tutors Guidelines Windows Linux Unix Mac Mail Network Software Web TheCAT Sitemap
arrowHome arrow Unix arrow SSH Port Forwarding Wednesday, 16 May 2012  
Unix
SSH Port Forwarding Print
Written by nibz   
Thursday, 17 November 2011

On Linux and Solaris systems it is common to use SSH to forward ports between two hosts. This short tutorial will introduce the -L, -R, and -D flags to ssh.

SSH -L stands for local forwarding. Its syntax is ssh -L port:host:hostport remotehost. This allows you to connect a local port to a remote port over an encrypted ssh tunnel.

To see it in action:

ssh -L 5901:localhost:5901 joeuser@nemo.ece.pdx.edu

This command forwards vnc over ssh so that the user can use vnc securely. The user can then connect to it using e.g. vncviewer localhost:1.

SSH -R stands for remote forwarding. Its syntax is ssh -R port:host:hostport remotehost. This allows you to connect a remote port to a local port over an encrypted ssh tunnel.

To see it in action:

ssh -R 5800:localhost:22 joeuser@nemo.ece.pdx.edu


This command forwards port 22 from the host machine into port 5800 on nemo.ece.pdx.edu. This means you can ssh nemo.ece.pdx.edu -p 5800 and it will be the same as sshing into the original box.

SSH -D is for dynamic application-level port forwarding. Its syntax is ssh -D port remotehost. It allows you to put up a SOCKS proxy over an encrypted ssh tunnel.
To see it in action:

ssh -D 2100 joeuser@nemo.ece.pdx.edu

This command forwards all trafic requested of localhost:2100 through nemo.ece.pdx.edu. You can configure Chromium or Firefox to use localhost:2100 as a SOCKS5 proxy and be sure that all your http traffic is being tunneled over ssh.

When to use which one:

SSH -L is good for exposing a remote port locally. SSH -R is good for accessing a box hidden behind a NAT. SSH -D is good for tunneling your web traffic in an environment you don't completely trust.

Last Updated ( Thursday, 17 November 2011 )
relics - vt1000
relics - vt1000
Upcoming Events
There are no upcoming events currently scheduled.
View Full Calendar

©1999 - 2012 TheCAT