Saturday, August 11, 2012

SOCKS Proxy over SSH with OpenSSH (Linux) or PuTTY (Windows)

Do you want to use a proxy for surfing Internet without using untrusted proxies? If you have a SSH account to a server with an Internet connection, this article will show you how to create your own SOCKS proxy for above purpose. I will also show you how to do that on both Linux and Windows.

1. Create SOCKS Proxy

Linux

On Linux, all you need is an OpenSSH client which is normally installed by default by almost distros. Open Terminal and run the following command to create a SOCKS proxy which listens for connections on port 1080.

$ ssh -D 1080 username@hostname

A more advantage command which I normally use is as follow.

$ ssh -NCf -o "ServerAliveInterval 300" -D 1080 username@hostname

Please check the man page of ssh for options.

Windows

PuTTY might be the most popular SSH client on Windows. Fortunately, it also supports SOCKS proxy. You should use the latest version which can be downloaded from here.

Open PuTTY an declare information such as host name as normal.

The main window of PuTTY where you can declare host name, port, etc.
The important part is to open a port for listening locally as a SOCKS proxy. Change to "Tunnels" category; fill the port to "Source port" and choose "Dynamic"; click on "Add" button.


Now, you can back to the "Session" category and click on "Open" button to log in to your server.

To avoid session timeout, you should tell PuTTY to send some null packets to the server after some duration. To do that, go to "Connection" category and fill out the number of seconds between null packet sending.


That is enough for proxy. You now have a SOCKS proxy listening on port 1080. It is time to configure web browser redirect every connection via newly created proxy.

2. Web Browser Configuration

Firefox

If you use Firefox, you can set the proxy information by accessing "Options" dialog on Windows or "Preferences" dialog on Linux. Then change to "Advanced" category; choose "Network" tab and click con the "Settings..." button.


Declare the proxy information as in the following screenshot.


Click on OK and OK again. That's all! You now can access to an IP check service to confirm that your web connection routed via the proxy. You can try IP2LOCATION.

Chrome and Internet Explorer

Both Google Chrome and Internet Explorer use the system settings for the proxy. You can declare the information by opening "Internet Options" dialog from Control Panel or Internet Explorer or Chrome.


Change to "Connections" tab and click on "LAN settings" button.


On the "Local Area Network (LAN) Settings" dialog, un-check "Automatically detect settings" and check on "Use a proxy server for your LAN (These settings will not apply to dial-up or VPN connections)." Then click on "Advanced" button.


Declare information as in the above screenshot and click on OK.

On Google Chrome, you can open the system proxy settings by choosing "Settings -> Show advanced settings... -> Change proxy settings..."

Hope this article is useful to you, sometime ;).


No comments: