I'm using Debian Lenny and I want to tunnel rtorrent only through a OpenVPN tunnel.

I have a tunnel running, the config file looks like this:

dev tun
proto udp
remote openvpn.xxx.com 1194
resolv-retry infinite
ca /etc/openvpn/xxx/keys/ca.crt
cert /etc/openvpn/xxx/keys/client.crt
key /etc/openvpn/xxx/keys/client.key
tls-auth /etc/openvpn/xxx/keys/tls.key 1
ns-cert-type server
verb 3
script-security 3
reneg-sec 0

My idea is that I could run a sockd proxy internally that redirects traffic to the openvpn tunnel. I could use the *nix "proxifier" application "tsocks" to make it possible for rtorrent to connect through that proxy (as rtorrent doesn't support proxies).

I have trouble configuring sockd as my IP inside the VPN changes every time I connect. This is a config file someone said would help: http://ircpimps.org/sockd.conf As my IP changes at each connect I don't know what to put in that config file. I have no control over the host side config file.

Any help wanted. Any other method is very welcome.


You have to mark the packets for this application somehow. The easiest way to do this would be the following:

  • Run rtorrent as an own user
  • Use iptables to mark the connections from the rtorrent user (-m owner --uid-owner rtorrent)
    • Alternatively you could also match the PID (--pid-owner)
  • Use policy routing to route those connections differently from your "normal" routing table.

The detailed explanation would be beyond useful if written here, but this should give you enough keywords to google for.


One other way to solve it could be to use socks ower ssh (ssh -D portnumber) which works fine with tsocks.


A SOCKS proxy is probably not the best tool for this job. The way I have this set up is:

  1. Run rtorrent as a specific user
  2. Use iptables to forward traffic from that user over the VPN

The question is mainly if you want to run rtorrent as a different user. You are most likely running it inside screen, and screen is not a big fan of su'ing to it's user. It is doable, but an extra thing you will need to figure out.

When researching this exact question for my setup, I found it to be extremely hard to limit the OpenVPN on a process-level. If you can find a way to make it work, I would sure be interested.


Tell rtorrent to only listen to tun0 or whatever IP is assigned to it. This should take care of incoming connections.

I don't know what "sockd" is but tsocks configuration file is /etc/tsocks.conf IIRC. But you need a socks-aware application at the other side and OpenVPN is not.

Looks like you can tell rtorrent to confine the ports it uses for outgoing connects to a specific range. Do this, and then use iptables to REDIRECT outgoing traffic on those ports from eth0 to tun0.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.