How to open network connections in a ssh tunnel (port forwarding)

Example of Telnet and FTP forwarding

Last update: 1-Feb-2002

Example 1: Telnet Forwarding

If you want to open an interactive login (telnet) on a remote host (without ssh) forwarding packets into a ssh tunnel, perform the following steps:
  1. From a machine with ssh client <Host A> login on the remote machine having ssh server <Host B> issuing the command:
    ssh -L 2323:<Host C>:23   <Host B>

  2. Now on the Host A:
    telnet <Host A> 2323


Example 2: FTP Forwarding

If you want to open a File Transfer session (FTP) on a remote host (without ssh) forwarding packets into a ssh tunnel, perform the following steps:
  1. From a machine with ssh client <Host A> login on the remote machine having ssh server <Host B> issuing the command:
    ssh -L 2121:<Host C>:21   <Host B>

  2. Now on the Host A:
Note:
The numbers 2121 and 2323 are only two examples of casual choise of the user (the only rule is that they must be greater than 1024). If you get an error issuing the ssh command, it's possible that the choosed port (2121 or 2323) is already allocated by another application. In this case you can try another number.


[ LNF Home page | Computing Home page | SSH @ LNF ]