Dynamically Bind rTorrent to VPN IP Address on Synology DSM5
rTorrent has the ability to bind to a specific IP Address, which is handy when you want to have all of your torrent traffic flowing over a certain internet connection (such as a VPN). Unfortunately, rTorrent does not have the ability to bind to a specific network interface. This is unfortunate because in larger VPN services, such as PrivateInternetAccess, your IP address changes frequently. This means we have to constantly edit our rTorrent config file and restart rTorrent when our network interface IP address changes.
I have been searching for a while now for how to pick up changes to the PrivateInternetAccess VPN IP address (which changes every few hours), have the rTorrent config bind section reflect this change, and restart rTorrent on my Synology NAS running DSM 5.
I first started out believing that I had to find a way to install cron on the Synology in order to achieve this. I could not find a single relevant article/blog-post/tutorial detailing how to get cron installed and working on DSM 5. Luckily, it turns out that DSM 5 does have support for a Task Scheduler that can run arbitrary user-defined scripts!
Here's how to get a task to run on Synology DSM5 to update the rTorrent config file with the current VPN IP address:
WARNING! Back up your existing rTorrent.rc file first! Mine is in /volume1/@appstore/rtorrent/var/.rtorrent.rc
Log into the Synology Diskstation web interface as any admin.
Open up the Control Panel.
Click on the Task Scheduler.
Click the "Create" drop-down, and then select "User-defined script".
Give the task any name you wish, for example "rTorrent VPN bind".
I left the user as root — use any user who has sufficient permissions to edit files and restart services.
As for the actual "User-defined script", I have created this Gist, edit/change it to suit your needs:
https://gist.github.com/JohnPostlethwait/d9b1b8da830410e3287b
For the "Schedule" tab I have mine run at the greatest frequency it currently allows, which is daily, every hour. Make sure to put the "First run time" as 00:00 and the "Last run time" as 23:00 Otherwise it will only run once a day...
Save this script by clicking on the "OK" button.
optional: Select this script from the table, and click "Run" just for the hell of it...
That is it! Your rTorrent config file should now be updated every hour (or so), have rTorrent restarted to pick up the changes, and your torrents continued to be downloading over the VPN.
I hope this helps someone out there...
Note: There is no error-reporting in user-defined scripts, so if this does not seem to be working for you, try copying and pasting the relevant lines out of the above Gist and running them manually when SSH'd into the Synology.


















