Verfasst von: hugahaga | 8 April 2010

How to open multiple SSH tunnels – CertPal

I use remote linux services often and exposing them as local services can be performed securely using SSH. For example you can access a tomcat server or email server hosted at IP 1.2.3.4 by opening a secure SSH tunnel between your local machine and the target address – 1.2.3.4.

The OpenSSH tool can be used to perform SSH related activities on your machine. Simply install it with yum, apt-get or Yast, if it is not already available. Once you have it use the following command to open multiple SSH tunnels to your services

Open tunnel and execute commands:

1  
ssh 1.2.3.4 -lmyUser -L 3098:1.2.3.4:21 -L 3099:1.2.3.4:80 -L 3100:1.2.3.4:443

The command is explained below

1.2.3.4 – Your target IP

l – The user to login as

L – A local tunnel to a remote port

3098 – The local port to use when establishing this tunnel

21 – The remote port at 1.2.3.4 to which the tunnel will be established

Multiple tunnels can be opened by specifying multiple -L flags. For example http://localhost:3099 will now redirect to http://1.2.3.4:80/ That is a fancy way of saying all HTTP requests ( 80 is the default port ) for 1.2.3.4 can now be reached locally at port 3099.

Note that the above command will also log you into the remote system. If you want to open the tunnels alone, use the -N switch and the -f switch as shown below

Open tunnels only:

1  
ssh -f myUser@1.2.3.4 -L 3099:1.2.3.4:25 -N

The -f switch asks SSH to work in the background and -N asks SSH not to execute any commands.

Advertisements

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

Kategorien

%d Bloggern gefällt das: