I have previously written about how to use your Synology NAS to download torrents over a VPN connection using Synology Download Station and OpenVPN, this post shows you how to use your Torrent client of choice with OpenVPN inside a docker container. The benefit of doing it this way is primarily isolating the torrent client inside a container which utilises the VPN, while the remaining Synology services connect directly to the internet without the VPN connection.
Lets get started.
Step 1. Download and Install Docker from the Synology Package Center
Step 2. Open Docker and click on the Registry. Search for haugene/transmission-openvpn, click Download
Step 3. Create the DNS config file ‘resolv.conf’, open a text editor and type the name server of your choosing. I’m using the name servers provided by Private Internet Access:
nameserver 220.127.116.11 nameserver 18.104.22.168
Make sure the file doesn’t have a .txt file extension. Open Synology File Station and create a new folder:
Upload the ‘resolv.conf’ to the ‘transmission-openvpn’ folder
While your here, create your new downloads directory:
If you want to create a separate watch directory do so now.
Step 4. Create a VPN adapter script called ‘TUN.sh’, open a text editor and copy the following code:
#!/bin/sh # Create the necessary file structure for /dev/net/tun if ( [ ! -c /dev/net/tun ] ); then if ( [ ! -d /dev/net ] ); then mkdir -m 755 /dev/net fi mknod /dev/net/tun c 10 200 fi # Load the tun module if not already loaded if ( !(lsmod | grep -q "^tun\s") ); then insmod /lib/modules/tun.ko fi
As with the previous step, ensure the file doesn’t have the .txt extension. Upload to the same folder as before.
Upload ‘TUN.sh’ to the folder
Step 4. Schedule the TUN.sh script to run when the Synology boots. Open the Synology Diskstation management interface.
- Control Panel > Task Scheduler
- Create > Triggered Task > User Defined Script
- General > Task > Enter the following settings
Task : TUN.sh User: root Event: Boot-up
- Task Settings > Run-command > User Defined Script:
Click Okay and Run the task.
Step 5. Back to Docker, click Images, select the haugene/transmission-openvpn image and click Launch
Step 6. Configure the container with the following settings:
- General Settings > ‘Execute container using high privilege’
- Advanced Settings > ‘Enable auto-restart’
- Advanced Settings > Volume > Add Folder > Specify a mount path for /data/completed to /Downloads
- Advanced Settings > Volume > Add File > Specify the mount path for /etc/resolv.conf, as created in step 3.
- Advanced Settings > Port Settings > Specify which ports you want to connect to the container through
<localport>:<containerport>/<type> 9091:9091/TCP 16881:16881/TCP 6881:6881/UDP
- Advanced Settings > Environment > Specify your VPN credentials by setting the following variables:
OPENVPN_USERNAME: vpn_username OPENVPN_PASSWORD: vpn_password OPENVPN_PROVIDER: vpn_provider e.g. PIA OPENVPN_CONFIG: vpn_server e.g Sweden
Advanced Settings > Environment > Specify the user and group identifiers (this permits the container to use the same credentials as the user, to avoid any permissions issues which can arise when specifying a user created share outside the docker folder as the download location)
PUID: USER_ID e.g. 1000 PGID: GROUP_ID e.g. 1000 TZ: Time Zone e.g. Europe/London
To determine your PUID and GPID open a terminal window and type the following command:
If you want to specify a block list set the following variables:
blocklist-enabled: true blocklist-url : blocklist_URL
If you want to enable seeding then the server needs to have port forwarding enabled, check with your VPN provider which servers use port forwarding.
Apply the settings.
Step 7. Run the container. Check the port number for user interface
- Details > Overview > Port Settings
Step 8. Open the management interface via:
Check the VPN connection is working, follow the instructions here.
You should now be able to start adding torrents, which will download over the VPN and when finished by moved to the downloads folder you specified. There are a couple of plug-ins available for Firefox and Chrome which allow you to manage magnet links and also monitor the download status in the browser toolbar without opening the management UI.
My personal preference is Transmitter for Transmission in Firefox and Remote Transmission ++ in Chrome.
If you want to use another Torrent client, there are other Docker images available.