Transmission VPN

GitHub Releases GitHub Top Languages GitHub License Become a GitHub Sponsor

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:

  1. Create the VPN using DiskStation Manager
  2. Install Transmission from SynoCommunity's repo
  3. Fill out the VPN Settings/Optionals (below)

Retrieve Variables

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 Settings
  1. __VPN_CONFID__ - Synology Configuration ID (e.g. l1234567890, instructions below)
  2. __VPN_CONFNAME__ - Synology Configuration Name (l2tpclient, pptpclient, or ovpnclient)
  3. __VPN_PROTO__ - Synology Protocol (l2tp, pptp, or openvpn)
  4. __VPN_UINAME__ - Synology VPN Name (Control Panel > Network > Network Interface)
VPN Optionals
  1. __VPN_TYPE__ - The type of connection you will route though (ppp for L2TP/PPTP VPN, or tun for OpenVPN)
  2. __VPN_INTERFACE__ - The default interface you will be connecting to (ppp0 for L2TP/PPTP, or tun0 for OpenVPN)
  3. __VPN_RETRY__ - How many retries (times) if VPN fails to connect (default is 10)
  4. __VPN_INTERVAL__ - The time (in seconds) to wait between each retry (default is 30)
VPN Features
  1. __PORT_FWD__ - Carries an additional port forwarding check (default is empty, 51413 for Transmission default)
  2. __IP_CHECK__ - Which URL to use to check your external IP address (default is http://ipinfo.io/ip)
App Settings
  1. __TRANS_USER__ - The user running under Transmission (default is sc-transmission)
  2. __TRANS_GROUP__ - The group of Transmission's user (default is transmission)
  3. __TRANS_VAR__ - Path where the settings.json file is located (full path, no ending backslash)

Get Synology Configuration ID

To retrieve the VPN_CONFID, follow these steps:

  1. SSH or Telnet into your Synology DiskStation
  2. Type cd /usr/syno/etc/synovpnclient/
  3. Type cd PROTOCOL (Replace PROTOCOL with l2tp, openvpn, or pptp)
  4. Type in ls -l to list out the files
  5. Find a file called __connect_l1234567890__
  6. Copy the text l1234567890 to the VPN_CONFID above
  7. 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.

Task Scheduling

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

How to Use this Script

Before you use this script, use the following commands:

  1. sh transmission-vpn.sh install - Installer. Stops VPN, binds 127.0.0.1 to Transmission
  2. sh transmission-vpn.sh uninstall - Uninstaller. Stops VPN, binds 0.0.0.0 to Transmission

To run this script, use the following commands:

  1. sh transmission-vpn.sh start - Start. Starts the VPN, binds VPN address to Transmission
  2. sh transmission-vpn.sh stop - Stop. Stops the VPN, binds 127.0.0.1 to Transmission
  3. 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.

No Internet Bug Fix

If this script took Transmission offline (cannot download), follow the instructions below:

  1. In your DiskStation Manager
  2. Go to Control Panel > Network > General
  3. Click Advanced Settings
  4. Check Enable Multiple Gateways
  5. 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.

Wrong VPN Interface

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:

  1. In your DiskStation Manager
  2. Go to Control Panel > Network > Network Interface
  3. Select your VPN, then click Connect
  4. Once connected, SSH or Telnet into your NAS
  5. Type ifconfig into the Terminal
  6. Find the VPN interface. It should NOT be eth0 or lo
  7. Copy the interface name (left of Link encap:)
  8. Replace the VPN_INTERFACE with the copied interface name
  9. Restart the Transmission VPN script

Port Forwarding Limitations

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.

Transmission Vpn

Route Transmission though PPTP, L2TP/IPSec, OpenVPN on Synology NAS

Transmission Vpn Info

⭐ Stars18
🔗 Source Codegithub.com
🕒 Last Update10 months ago
🕒 Created7 years ago
🐞 Open Issues0
➗ Star-Issue RatioInfinity
😎 Authormrjackyliang