tsocks

Someone at work pointed out a cool utility called tsocks.

tsocks allows non-SOCKS-aware applications (e.g.: telnet, ssh, ftp, etc.) to use SOCKS without any modification. It does this by intercepting the calls that applications make (i.e.: through LD_PRELOAD) to establish network connections and negotating them through a SOCKS server as necessary.

Installing it on a Debian-based system is as easy as:

$ sudo apt-get install tsocks

I then edited my /etc/tsocks.conf file to have this:

local = 192.168.1.0/255.255.255.0
local = 10.0.0.0/255.0.0.0

server = 127.0.0.1
server_type = 4
server_port = 1080

The last part is the most important part and is basically telling tsocks that it’s going to proxy all of my connections through a SOCKS 4 proxy at localhost:1080 (this SOCKS proxy comes from the fact that I have a “DynamicForward 1080” line in my ~/.ssh/config for the ssh proxy that I use to connect to work).

Then I can access machines behind the corporate firewall by invoking tsocks in “one-off” fashion like this:

$ tsocks ssh somehost.firewalleddomain.net

or if typing “tsocks” in front of each of your commands is too much trouble, tsocks can be turned on and off semi-permanently so you can do stuff like this:

$ source /usr/bin/tsocks on
$ ssh host1.firewalleddomain.net
$ ssh host2.firewalleddomain.net
$ source /usr/bin/tsocks off

Neat concept. Interesting use of LD_PRELOAD.

One thought on “tsocks

Leave a Reply

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