I'd like to ensure that transmission only sends/receives traffic when the server it runs on is connected to a VPN.
I found this question which is similar but I don't want to force all traffic through the VPN and I haven't been able to find a good guide on how to use firestarter from the command line.
Instead I was thinking of using ufw, but I have little to no experience with firewalls, and I'm hoping the community can help me out.
One idea I had would be to force transmission to use a specific port, say 33442, and then only allow traffic to and from that port from the IP address of the VPN server. I checked out the Ubuntu server guide and I think could do something like this:
sudo ufw enable
sudo ufw deny port tcp from localhost to any port 33442
sudo ufa allow port tcp from localhost to VPNIP port 33442
sudo ufw deny port udp from localhost to any port 33442
sudo ufa allow port udp from localhost to VPNIP port 33442
Does this logic hold its salt? How would you do it? What would I use for VPNIP, the public IP of the VPN server, or should I specify the local subnet range that the VPN connects me to?
Thanks for your help!
Create
vpnroute
group:Add an
iptables
rule that rejects any outgoing network connection made by members of thevpnroute
group that does not go throughtun0
interface:Start transmission process as a member of
vpnroute
group:Here is a complete 'HOW TO' for NOOBS (using debian) on making sure the debian-transmission user group (i.e transmission) only routes data through the vpn
DO NOT use the more lengthy 'How to' for vpn based on complex system scripts...! iptables is THE BEST (and foolproof) METHOD!!! - USING A FEW IPTABLE RULES based on the transmission user and group to control the vpn (not like many more complex 'hack' methods which use systemd scripts, up and down scripts etc...) and it's soooo simple!
Step 1 - Setup: (Assumes transmission is installed and debian-transmission user therefore exists!)
Step 2 - Create the transmission-ip-rules file
and add the text in the code block below starting from
#!/bin/bash
IMPORTANT
Save the file and then run
then make sure these rules persist between reboots with:
and tap yes to both prompts. DONE!
What is great about this script is that it will track all data through the device! When you issue
it will show how much data is going to which interface and which side INPUT or OUTPUT so you can be assured that the vpn script is working properly. Eg;
This script has been exhaustively tested on connects, disconnects, reboots from the vpn. It works great. Transmission can ONLY use the VPN. The great advantage of this script over the others is that I have made sure as you can see (via
iptables -L -v
) that your data tallies with what is pulled over transmission (by adding INPUT (all) and Forward (all) rules for each interface eth0, vpn (tun0)). So you know exactly whats happening!!! The data totals will not tally exactly with transmission - Unfortunately I cannot discriminate on the INPUT side down to the debian-transmission user, and there will be both extra overhead and perhaps other processes using the same VPN, but you will see the data roughly tallies on the INPUT side and is about half on the OUTPUT for the vpn confirming its working. Another thing to note - it take a while on a vpn disconnect (all traffic stops with transmission) and reconnect for transmission to 'get going' on the new vpn so don't worry if it takes about 5 mins to start torrenting again...TIP - google 'MAN iptables' and see this article on bandwidth monitoring if you want to know line by line how this script works...
This works for a headless transmission, I am restricting traffic based on the user that is running the transmission service,
10.0.0.0/8
is your internal network you should change it to match your network,tun0
is your OpenVPN interface,eth0
is your LAN connection.Add
sudo
to commands, if you are not root:iptables -F
(We used the -F switch to flush all existing rules so we start with a clean state from which to add new rules.)iptables -L
(list current setup)make the iptables persistent after restart
Ideally you should use a torrent client that has a feature to bind to a specific interface (the VPN interface).
Among torrent clients, Deluge does this. So you can install Deluge and configure the interface in the Preferences and you are set!