Transmission Over OpenVPN

In general, all of your network traffic should use your VPN connection, if it is active, so by default Transmission should tunnel all of your torrent traffic over the VPN. That's fine until your VPN connection drops and all of your torrent traffic starts using your regular internet connection, which is kind of what we were trying to avoid with the VPN in the first place.

While OpenVPN is usually pretty good about reconnecting if the connection is lost, it's better if that doesn't happen, so in this tutorial we'll setup Transmission to only route our torrent traffic through the VPN, and if the VPN is not connected Transmission will just stop torrenting until the VPN is reconnected.

We need to create a template of our transmission-daemon setting.json file so that we can update the ip address that we download torrents through every time the VPN connects:

sudo cp /etc/transmission-daemon/settings.json /etc/transmission-daemon/settings_template.json

Open /etc/transmission-daemon/settings_template.json in your favorite text editor (as superuser) and change the following value:

    "bind-address-ipv4": "IP_ADDRESS",

Now setup a new script that OpenVPN will call when a VPN connection is successfully established.

sudo touch /etc/openvpn/
sudo chmod +x /etc/openvpn/

Open /etc/openvpn/ in your favorite text editor (as superuser) and set it up like this:


/etc/init.d/transmission-daemon stop
sed s/IP_ADDRESS/$4/ /etc/transmission-daemon/settings_template.json > /etc/transmission-daemon/settings.json
/etc/init.d/transmission-daemon start

Now edit your script from the OpenVPN tutorial and update it to look like this:


sudo openvpn --config /path/to/your/openvpn/config/file --script-security 2 --up /etc/openvpn/

From now on, when you connect to the VPN it will force your torrent traffic to use the VPN connection, and if you get disconnected it should stop torrenting until you reconnect. You can use a tool like CheckMyTorrentIP to ensure that your torrent traffic is going over the VPN correctly.

comments powered by Disqus