Monday, May 19, 2008

Socks Tunneling, Muaaah....

ssh has this very cool feature called dynamic port forwarding which acts as a SOCKS 5 proxy.

When I am in a bandwidth limited network (usually my university has not so good international connection, plus my home isp sucks), i connect to my server which is in NPIX through ssh and forward a local port in my machine to act as a socks proxy.

I then configure firefox to use the particular proxy and browsing becomes pleasent.

Until now I hadn't thought about using any other application other than firefox, I use downthemall to download files so that was sufficient.

Yesterday while updating my system, i needed to forward synaptic through the tunnel. Since synaptic only supports http proxy and not socks proxy, i was going nuts.

Thanks to tsocks, that problem has been solved.

Through tsocks, you can forward all the network activity of a program through a socks proxy, so just running synaptic or apt-get after tsocks means using the alternative bandwidth that we get :-) .

The whole system is as belows.

a) Connecting to a remote server and opening a socks proxy in local machine

bibek@godzilla:~$ ssh bibek@10.1.1.2 -D 1080
bibek@10.1.1.2's password:
Linux chichekServer 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
Last login: Mon May 19 17:43:14 2008 from 10.1.1.1
bibek@chichekServer:~$


godzilla is my main server and chichekServer is my remote machine, through godzilla i logged into chichekServer and during that time, opened port 1080 in my local machine,

All i need now is to put the socks proxy name in firefox as below



Time to install tsocks in my home machine
bibek@godzilla:~$ sudo aptitude install tsocks

Configure tsocks to use localhost:1080 as proxy server
the last three lines of /etc/tsocks.conf are

server = 127.0.0.1
# Server type defaults to 4 so we need to specify it as 5 for this one
server_type = 5
# The port defaults to 1080 but I've stated it here for clarity
server_port = 1080


Now lets use tsocks to tunnel apt-get
bibek@godzilla:~$ tsocks apt-get install kde4

This should tunnel your application through the socks proxy. If you want to tunnel any other application just put tsocks in front of it.

This way we the benefit is we can tunnel even p2p applications through the socks proxy, which isn't possible through normal http proxies.

Cheers