Enforcing an application, for example a torrent client like Transmission, to always use the VPN interface or any particular network interface for that matter, is trivially simple using iptables on Debian, Ubuntu or any other GNU/Linux distro.
Personally, I am running Debian Sid on the Raspberry Pi. Occasionally I use it for downloading files ( legal stuff, seriously, believe me :D ) using Transmission Bittorrent client over a VPN connection. Sometimes it happens that the VPN connection fails and doesn't reconnect for whatever reason and Transmission continues pulling stuff directly over my internet connection, which I would like to avoid. Fortunately it is very straightforward to enforce rules based on application owner UID. Transmission runs under the owner debian-transmission in Debian (use htop to check this) and the following two lines of iptables ensures that any process with owner having UID, debian-transmission, will not use any other network interface apart from the OpenVPN tunnel interface tun0
The first line ensures that, my Mac-mini having IP address 192.168.0.100 on the lan, can always access the web interface of transmission. The second line makes sure, no outgoing traffic can leave via anything other that tun0.
Peace of mind restored, thanks to iptables.
Personally, I am running Debian Sid on the Raspberry Pi. Occasionally I use it for downloading files ( legal stuff, seriously, believe me :D ) using Transmission Bittorrent client over a VPN connection. Sometimes it happens that the VPN connection fails and doesn't reconnect for whatever reason and Transmission continues pulling stuff directly over my internet connection, which I would like to avoid. Fortunately it is very straightforward to enforce rules based on application owner UID. Transmission runs under the owner debian-transmission in Debian (use htop to check this) and the following two lines of iptables ensures that any process with owner having UID, debian-transmission, will not use any other network interface apart from the OpenVPN tunnel interface tun0
pi@sam-berry ~ $ sudo iptables -A OUTPUT -m owner --uid-owner debian-transmission -d 192.168.0.100 -j ACCEPT
pi@sam-berry ~ $ sudo iptables -A OUTPUT -m owner --uid-owner debian-transmission \! -o tun0 -j REJECT
The first line ensures that, my Mac-mini having IP address 192.168.0.100 on the lan, can always access the web interface of transmission. The second line makes sure, no outgoing traffic can leave via anything other that tun0.
Peace of mind restored, thanks to iptables.
Comments
Unfortunately, issuing this command closes Transmission's listening TCP port and also prevents Chromium from connecting.
I'd appreciate any advice you might have!
Andy
The rule should only apply to processes with owner "debian-transmission".
You can list the iptables rules using
sudo iptables -L
and check whether the rule was created successfully.
Also I unblocked my whole local network with
iptables -A OUTPUT -m owner --uid-owner torrent -d 192.168.178.0/24 -j ACCEPT
root@debian:/etc# iptables -A OUTPUT -m owner --uid-owner debian-transmission \! -o tun0 -j REJECT
iptables v1.4.14: owner: Bad value for "--uid-owner" option: "debian-transmission"
Try `iptables -h' or 'iptables --help' for more information.
Any ideas?
Thanks!!
root@debian:/etc# iptables -A OUTPUT -m owner --uid-owner debian-transmission \! -o tun0 -j REJECT
iptables v1.4.14: owner: Bad value for "--uid-owner" option: "debian-transmission"
Try `iptables -h' or 'iptables --help' for more information.
Any ideas?
Thanks!!
Seems like for some reason, iptables is failing to perform a username lookup.
Manually find out the numeric uid of debian-transmission from the /etc/passwd file (should be the third field in the row).
Then try the iptables command, replacing "debian-transmission" with its equivalent numeric userid.
Hope it helps.
root@debian:/home/jwhitakermcrae# ps aux | grep trans
1000 26718 2.4 0.1 437028 21376 ? Sl 10:48 0:00 transmission-gtk
root 26727 0.0 0.0 7828 880 pts/1 S+ 10:49 0:00 grep trans
Thanks for the help!!
when adding both rules to my system I get no connection anymore. I have forwarded one Port from my VPN-ISP (AirVPN) and set the same port to my transmission. Transmission says that the port is "closed". Also it seems not to be able to connect to the tracker. It just gets the message "Announce Error - Could not connect to tracker."
Any suggestions whats going wrong here?
I am using Ubuntu 12.04.4 LTS.