Transmission (seedbox) over VPN using OpenVPN

Transmission (seedbox) over VPN using OpenVPN

We have seen how to make Raspberry Pi a seedbox using Transmission using debian based distro, openSUSE and arch linux. Of course there are alternatives such as Deluge or rTorrent.

All of your network traffic should use your VPN connection, if it is active, so by default Transmission should tunnel all of your torrent traffic over the VPN. That's fine until your VPN connection drops and all of your torrent traffic starts using your regular internet connection, which is kind of what we were trying to avoid with the VPN in the first place.

In this tutorial we'll setup Transmission to only route our torrent traffic through the VPN, and if the VPN is not connected Transmission will just stop torrenting until the VPN is reconnected.


OpenVPN installation


First of all, let's install OpenVPN.

sudo apt-get update && sudo apt-get install openvpn

Create a directory in your home directory and download the OpenVPN files from your provider.

cd ~/
mkdir vpn
cd vpn

We will test with VPNbook. But there are plenty of great providers you can choose.

FOR VPNBOOK

Download the files that doesn't say web surfing only; no p2p (for us it's PL226 Server OpenVPN Certificate Bundle and DE4 Server OpenVPN Certificate Bundle. But you better check often for changes).

Decompress the zip files and you'll have files such as

vpnbook-de4-tcp80.ovpn
vpnbook-de4-tcp443.ovpn
vpnbook-de4-udp53.ovpn
vpnbook-de4-udp25000.ovpn
vpnbook-pl226-tcp80.ovpn
vpnbook-pl226-tcp443.ovpn
vpnbook-pl226-udp53.ovpn
vpnbook-pl226-udp25000.ovpn

Make sure that those files are in the directory vpn in your home directory.

Create a file named password.txt in the same directory.

nano password.txt

And add the credentials you'll find at vpnbook page.

vpnbook
5bheau6u (that might change)

Now open one file

nano vpnbook-pl226-udp25000.ovpn

and find the auth-user-pass and point it to the txt file

auth-user-pass /home/USER/vpn/password.txt

That way you don't need to type the username and password every time you run the command.

Then, create a script to start your vpn connection and make it executable:

touch vpn.sh
chmod +x vpn.sh

Now edit your vpn.sh script to look like this:

#!/bin/sh

sudo openvpn --config /home/USER/vpn/vpnbook-pl226-udp25000.ovpn --script-security 2

The name of the ovpn file might be different for you.

Now you should be able to execute this script to connect to your vpn:

./vpn.sh

Now you are connected to the VPN and all of your traffic should tunnel through there.

You can check your ip.

curl ipinfo.io/ip


Sources
* Naspberry pi OpenVPN
* OpenVPN forums (Password.txt file)
* OpenVPN on strech



Transmission Over OpenVPN


We need to create a template of our transmission-daemon setting.json file so that we can update the ip address that we download torrents through every time the VPN connects:

sudo cp /etc/transmission-daemon/settings.json /etc/transmission-daemon/settings_template.json

Open /etc/transmission-daemon/settings_template.json:

nano /etc/transmission-daemon/settings_template.json

And change the following value:

{
...
"bind-address-ipv4": "IP_ADDRESS",
...
}

Now setup a new script that OpenVPN will call when a VPN connection is successfully established.

sudo touch /etc/openvpn/up.sh
sudo chmod +x /etc/openvpn/up.sh

Open /etc/openvpn/up.sh (as superuser):

nano /etc/openvpn/up.sh

and set it up like this:

#!/bin/sh

/etc/init.d/transmission-daemon stop
sed s/IP_ADDRESS/$4/ /etc/transmission-daemon/settings_template.json > /etc/transmission-daemon/settings.json
/etc/init.d/transmission-daemon start

Now edit your vpn.sh script from the OpenVPN tutorial and update it to look like this:

#!/bin/sh

sudo openvpn --config /home/USER/vpn/vpnbook-pl226-udp25000.ovpn --script-security 2 --up /etc/openvpn/up.sh

From now on, when you connect to the VPN it will force your torrent traffic to use the VPN connection, and if you get disconnected it should stop torrenting until you reconnect.

Source
Transmission Over OpenVPN



Run in the background


Using screen as super user:

screen -S vpnbook -d -m ./vpn.sh

after that you can quit the terminal, also you can reattach to it by:

screen -r vpnbook

Another way to run in the background is by adding an &

/home/USER/vpn/vpn.sh &

But you have to run the command every time you reboot.

Source
Run Bash script in background and exit terminal

Some tutorials to check out:
* openvpn-install
* How to run your own OpenVPN server on a Raspberry PI
* OpenVPN Server raspberry pi /w PiVPN (video)

DISCLAIMER:
- All the above are for debian based distro. If you have another distro, check the directory of your json file.
- Change USER to your username.
- Download illegal torrents is prohibited. Please do not use this tutorial for illegal reason.

Δεν υπάρχουν σχόλια

Από το Blogger.