This is a special script for Synology NAS that helps you force Transmission's connection under the VPN you specify. It works with L2TP, PPTP, and OpenVPN connections. The script connects to VPN then sets Transmission to your VPN port. If it cannot find one, it will shut off VPN and prevent Transmission from working.
In other words, Transmission ONLY connects to VPN while other applications DO NOT!
To use this script, here are the steps you need to follow:
- Create the VPN using DiskStation Manager
- Install Transmission from SynoCommunity's repo
- Fill out the VPN Settings/Optionals (below)
These are the descriptions of the variables that may be changed depending on your configuration. Examples are located below and inside the script (transmission-vpn.sh
). If you need help, feel free to open an issue on GitHub!
- VPN_CONFID - Synology Configuration ID (e.g. l1234567890, instructions below)
- VPN_CONFNAME - Synology Configuration Name (l2tpclient, pptpclient, or ovpnclient)
- VPN_PROTO - Synology Protocol (l2tp, pptp, or openvpn)
- VPN_UINAME - Synology VPN Name (Control Panel > Network > Network Interface)
- VPN_TYPE - The type of connection you will route though (ppp for L2TP/PPTP VPN, or tun for OpenVPN)
- VPN_INTERFACE - The default interface you will be connecting to (ppp0 for L2TP/PPTP, or tun0 for OpenVPN)
- VPN_RETRY - How many retries (times) if VPN fails to connect (default is 10)
- VPN_INTERVAL - The time (in seconds) to wait between each retry (default is 30)
- PORT_FWD - Carries an additional port forwarding check (default is empty, 51413 for Transmission default)
- IP_CHECK - Which URL to use to check your external IP address (default is http://ipinfo.io/ip)
- TRANS_USER - The user running under Transmission (default is sc-transmission)
- TRANS_GROUP - The group of Transmission's user (default is transmission)
- TRANS_VAR - Path where the settings.json file is located (full path, no ending backslash)
To retrieve the VPN_CONFID, follow these steps:
- SSH or Telnet into your Synology DiskStation
- Type cd /usr/syno/etc/synovpnclient/
- Type cd PROTOCOL (Replace PROTOCOL with l2tp, openvpn, or pptp)
- Type in ls -l to list out the files
- Find a file called connect_l1234567890
- Copy the text l1234567890 to the VPN_CONFID above
- Type exit once to logout of SSH or Telnet
Note: The "l1234567890" ID is an example. Each configuration ID (per VPN connection) is UNIQUE and YOU MUST connect to your Synology NAS though SSH or Telnet to retrieve it.
If you want to automate the script, you can use the Task Scheduler application provided inside the DiskStation Manager. Make sure the script is ran under root to prevent any issues occurring.
This script is purely useful for checking if your Transmission connection is working properly, and breaks Transmission if the VPN connection is off to prevent a leak. Here is one scenario where I would use it:
- Run /volume1/transmission-vpn.sh repair every 1 or 5 minutes
Before you use this script, use the following commands:
- sh transmission-vpn.sh install - Installer. Stops VPN, binds 127.0.0.1 to Transmission
- sh transmission-vpn.sh uninstall - Uninstaller. Stops VPN, binds 0.0.0.0 to Transmission
To run this script, use the following commands:
- sh transmission-vpn.sh start - Start. Starts the VPN, binds VPN address to Transmission
- sh transmission-vpn.sh stop - Stop. Stops the VPN, binds 127.0.0.1 to Transmission
- sh transmission-vpn.sh repair - Repair. Fixes stalled VPNs, decides which IP address to bind
Note: If the script is located in /volume1/examplefolder/, navigate to that folder (using the cd command) before executing the commands above.
If this script took Transmission offline (cannot download), follow the instructions below:
- In your DiskStation Manager
- Go to Control Panel > Network > General
- Click Advanced Settings
- Check Enable Multiple Gateways
- Click OK then Apply
Note: Once this setting is enabled, you do not need to re-run the script. The internet for Transmission will start working immediately.
When running the start script for the first time, you might come across this error: ppp0: error fetching interface information: Device not found
.
Here's how you can fix this issue:
- In your DiskStation Manager
- Go to Control Panel > Network > Network Interface
- Select your VPN, then click Connect
- Once connected, SSH or Telnet into your NAS
- Type ifconfig into the Terminal
- Find the VPN interface. It should NOT be
eth0
orlo
- Copy the interface name (left of
Link encap:
) - Replace the VPN_INTERFACE with the copied interface name
- Restart the Transmission VPN script
If the script returns Network Port is closed
every time you run the repair script, please check if your VPN is connected behind a NAT device.
The script does not support checking ports behind NAT, as it will simply mark the specified port as closed
. If the VPN is behind a NAT device, make sure the PORT_FWD
variable is blank.
Note: The repair script will fail/restart when PORT_FWD
is not empty while behind NAT.