Using Tsocks to tranparently use SOCKS proxies in applications

There are not many applications out there supports SOCKS proxy for traffics. Usually people will try to find similar application that have SOCKS support if they need it. To Linux/BSD users, there is a dirty trick to do make virtually any console and some X applications to use SOCKS proxy transparently by preloading certain libraries before executing the application. One of those libraries is Tsocks.

Step 1 : Installing
Simply extract the tarball, then, use the magic spell everyone familiar with to install it.
sudo make install

Afterwards, create a config file named tsocks.conf in /etc/ . Refer the examples given together with the source tarball for guidance on how to write the config. For those who just want a quick and basic config and lazy to open the examples, I've provided it below.

# This is the configuration for libtsocks (transparent socks)
# Lines beginning with # and blank lines are ignored
# This sample configuration shows the simplest (and most common) use of
# tsocks. This is a basic LAN, this machine can access anything on the
# local ethernet (192.168.0.*) but anything else has to use the SOCKS version
# 4 server on the firewall. Further details can be found in the man pages,
# tsocks(8) and tsocks.conf(5) and a more complex example is presented in
# tsocks.conf.complex.example

# We can access 192.168.0.* directly
local =

# Otherwise we use the server
server =

Step 2 : Using the library
To make an application to use tsocks, using a terminal, simply do this
export LD_PRELOAD=/lib/
before executing the application from the terminal. Note that environment variable export only works on the terminal which you export the value.

Alternatives of Tsocks
Transconnect - A HTTP Proxying library similar to Tsocks.
Proxychains - A similar library which supports both HTTP and SOCKS. Also, its able to chain multiple proxies at once.


Anonymous said…
Just bumped into tsocks here (and Google brought me here ;D) as I was trying to find a way to make a script that uses urllib2 to connect to SOCKS5.

Apparently I'm not a Py guy and I don't know how to change the code from urllib2 to pycurl.


Popular posts from this blog

Announcing PlatoCDP, a Plone distribution for enterprises.

Adding simple popup to Plone frontpage

An Open Letter for the Rector of PETRONAS University of Technology