Tunnel web traffic through SSH [Linux]

This isn’t so much a guide as it is a reference point for the next time I want to do this and can’t remember how to do so. As it turns out is’ extremely easy but I have a way of making these things difficult and I didn’t disappoint this time round either.

What is it?

SSH tunnelling is the act of tunnelling your traffic through an SSH connection, enabling you to transport unencrypted data through a secure channel.

Why do I want to do this?

There are a few reasons why you might want to do this, the most obvious is that you’re behind a firewall or proxy which won’t allow you to access to a particular website or service. Perhaps you just want to access resources on your home network, or maybe your using free wifi somewhere and you’d just like to be more secure.

How do I do this?

In theory you shouldn’t have to make any changes to the server (the machine in which you will connect to via SSH), however you will need to ensure that the server has a public IP address; and if not then set up port forwarding on your router to your server.

Once done you can simply use the following command:

ssh -p 222 username@server.com -D 9001

-p 222 => The port to use for the SSH connection, by default this is 22 and you probably won’t need to set this

username@host => Should be self explanatory, this is the machine you wish to connect to via SSH. This will be your public facing IP.

-D 9001 => The port that we will listen to and tunnel through our SSH connection.

Configuring your browser

In whichever browser you are using, find the proxy settings and set up a SOCKS5 proxy for localhost on port 9001. Save your changes and off you go.

Help! It didn’t work!

Try appending -v (or -vvv for increased verbosity) to the end of the SSH command above in order to attempt to debug. If in doubt, leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *