5

Has anyone successfully set up a CLI-only (no web UI's!) torrent client that can tunnel all of its traffic through a VPN? (Either by sending all traffic through a particular interface or a SOCKS proxy)?

I have a Private Internet Access subscription and would like to use it to download torrent files on my headless Debian 7 machine without having to tunnel all of the traffic on my system.

2
  • What sort of traffic would you want not to go through the VPN?
    – jasonwryan
    Jul 21 '14 at 7:51
  • System updates, file downloads, really everything else. Most importantly, if I tunnel all of the system traffic I lose the ability to contact it with SSH.
    – Alex Ryan
    Jul 21 '14 at 17:31
3

The approach I would recommend is to route all your traffic through the VPN except SSH; this provides much more protection for your privacy and significantly reduces the risk of any personal information leaking.

This approach has several separate components.

Torrent client

rtorrent is an excellent torrent client for running in a headless environment. Run it in a tmux session so you can connect and disconnect at will.

Additionally, you can patch rtorrent with the canvas colour patch.

Routing traffic

Essentially, you want to set up packet filtering for all traffic on a specific port (your SSH port, here assumed to be non-standard 666) and interface (eth0). You can discover your gateway (here 192.168.1.1) with route -n. You will also need iproute2 installed for this:

ip rule add fwmark 65 table novpn
ip route add default via 192.168.1.1 dev eth0 table novpn
ip route flush cache
iptables -t mangle -A OUTPUT -p tcp --sport 666 -j MARK --set-mark 65
iptables -A INPUT -i tun0 -p tcp -m tcp --dport 666 -j DROP

Once you have it all setup and working, you'll need to script it to run at boot. See Ben. D's answer on Serverfault for a full walkthrough.

Browsing

Surfraw is excellent for command line browsing, and can hand off to w3m for loading the returned results.

Thanks to Gilles excellent answer here, it is possible to bind a key in w3m to trigger the magnets script from the rtorrent wiki. So, with this in your w3m config:

extbrowser /home/alex/bin/magnets %s

when you navigate to a magnet link, you can send it to rtorrent. See this post for the details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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