SSH Tunnels

If you have ever experienced you couldn't connect to something because you came from the wrong ip, you might find a solution here. Maybe trying to send emails, connect to trusted servers etc.

All of these commands requires you have a SSH client on your computer.

Forward

With this command you can use a ssh account to work as proxy for your connection.

ssh -nNT -L <local listen port>:<dest ip/host>:<dest port> <user>@<ssh ip/host>

The "-n" option tells ssh to associate standard input with /dev/null, "-N" tells ssh to just set up the tunnel and not to prepare a command stream, and "-T" tells ssh not to allocate a pseudo-tty on the remote system.

So if you wan't to forward your localhost port 4123 to google, you should do like this:

ssh -nNT -L 4123:google.com:80 <user>@<ssh ip/host>

Reverse

If you want to make it possible for people to connect to you this is the syntax to use:

ssh -nNT -R <remote listen port>:<remote listen ip>:<local dest port> <user>@<ssh ip/host>

Using this in an example you can imagine that you want to ssh to a server in a private network from a public server. Normally this is impossible due to router/firewall. With this example you can:

ssh -nNT -R 8822:localhost:22 <user>@<ssh ip/host>

Running this command from your local machine, opens a tunnel so you can ssh to localhost:8822 on the remote server, and get a connection with your local machine.

ssh -nNT -L <local listen port>:<dest ip/host>:<dest port> <user>@<ssh ip/host>

Comments:

Leave a Reply



(Your email will not be publicly displayed.)

Please type the letters and numbers shown in the image.Captcha CodeClick the image to see another captcha.