Security Art Work

Blog de Seguridad de la Información de S2 Grupo

Un blog de

Introduction to SSH tunnels

26 de November de 2012 Por José Vila

(Please note this post was originally published in the Spanish version of Security Art Work last 19th Jul 2012)

All of us have at some time found that the service we wanted to access is on a computer unreachable from our network or other similar problems. If we have SSH access we can easily solve problems like this using SSH tunnels.

We propose a first scenario, in which we have a database server protected by a firewall that prevents us directly interact with the database but that can be accessed by SSH (assuming MySQL, which uses port 3306).

In this case, to gain local access to the database, we will make all traffic going to local port X to be redirected through the SSH connection to local port 3306 of the machine to which we are connecting, using the tt>-L switch:

ssh -L X:localhost:3306 172.16.1.100

Now, if we have an application that uses that database server, we simply must tell the app that that the database is on our local computer on port X. Similarly, if the database it is in a third computer, to which we do not have access from our local computer but we do from the server to which we connect through SSH, the order would be:

ssh -L X:172.16.1.111:3306 172.16.1.100

We may also want just the opposite: that a remote server can access a resource or service provided by our computer or our local network.

In this case, we will redirect to port Z of our computer all the traffic that the remote server sends to its Y port, using the -R switch:

ssh -R Y:localhost:Z 172.16.1.100

Just as in the previous case, if the computer that provides the service that we want to connect to is different from ours, we will change localhost with the IP address of that computer. For example:

ssh -R Y:192.168.0.123:Z 172.16.1.100

As an extra, note that SSH servers offer another interesting feature, which consists of creating a SOCKS proxy on the local computer. With this we can do that all requests that are sent to the X port on the local computer to be redirected to the remote computer and sent to their destination as if the remote computer would have sent them:

ssh -D X 172.16.1.100

This is especially useful since there are many applications whose traffic can be forwarded through a SOCKS proxy. The best example of this are modern browsers, such as Firefox, for example:

We hope you enjoyed this small post.

FacebookX (Twitter)LinkedIn
  • Español

Pages

  • About
  • Authors
  • Cookies Policy
  • Guest posts
  • Legal Notice
  • Privacy Policy

Search

Authors

  • Antonio Villalón (228)
  • Manuel Benet (226)
  • Antonio Sanz (108)
  • Colaboradores (88)
  • Maite Moreno (73)
  • Roberto Amado (61)
  • José Rosell (59)
  • Joaquín Moreno (54)
  • Josemi Holguín (54)
  • Joan Soriano (52)
  • Jose L. Villalón (50)
  • José Vila (43)
  • Nelo Belda (43)
  • Antonio Huerta (38)
  • Fernando Seco (38)

All authors

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
  • Licencia de uso
Datos editoriales:
Publicación: securityartwork.es
Edita: S2 Grupo Soluciones de Seguridad, S.L.
Lugar de publicación: Valencia, España
ISSN 3101-5913

Return to top of page

Copyright © 2026 · Genesis Framework · WordPress

Utilizamos cookies propias y de terceros para mejorar y analizar el uso que haces de nuestro site. Puedes cambiar la configuración, rechazarlas u obtener más información sobre nuestra política de cookies AQUÍ. Aceptar
Política de cookies

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT