Openssh is commonly used to recieve ssh client connections to Unix machines, giving a shell login and eventually user access, however the ssh program can be utilised in other ways. One of them is port forwarding, read this guide to learn some basic examples. ssh -L is the command and switch responsible for forwarding, for more in depth information on the rest of the ssh command syntax, issue the command man ssh
First of all, I will explain what a port forwarding does, acting as a forward or relay for network traffic from a source port to a destination port, for example forwarding traffic recieved on port 2500 on server1 to port 25 on server might be one use.
Suppose you run Apache web server on port 80 on a local workstation and want to also forward traffic from port 8082 to on the same local machine to the Apache server
In the examples below SSH will be used to setup that port forwarding service.
First I am checking I can connect to apache, the result below is good.
[root@littlemac ~]# telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Now I make sure that nothing else is running on port 8082 , the result is good.
[root@littlemac ~]# telnet localhost 8082
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host: Connection refused
Now we issues the ssh command, with the -L forwarding switch:
[root@littlemac ~]# ssh -L 8082:localhost:80 localhost
root@localhost's password:
Last login: Sun Sep 6 12:09:43 2009 from localhost.localdomain
Now we telnet port 8082 on our local machine as recieve a connection as it were port 80, success !
[root@littlemac ~]# telnet localhost 8082
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
^]
telnet> quit
Connection closed.





