Set Up a Streaming Media Server – Pt. 8 – Set up VPN
It’s a good idea to run your torrent downloads through an anonymous VPN. Unlike Usenet, which runs over SSL, torrents just use regular unencrypted traffic. Your ISP can see what you’re downloading. The MPAA and other officials can see all the peers for a particular download, and they can see your IP address. We just want to download our movies in peace without getting copyright notices in the mail.
A VPN is basically an encrypted tunnel that you can send certain internet traffic through. In our example, we will make sure our torrent traffic goes through the VPN tunnel and comes out the other end somewhere else far from us with a different IP address associated with it. One service I like is Private Internet Access. In this tutorial, we’ll just assume that’s what we’ll be using.
We need to install OpenVPN. This is the software that’s used to connect to the VPN.
cd ~ wget https://www.privateinternetaccess.com/installer/install_ubuntu.sh sudo apt-get install network-manager sudo sh install_ubuntu.sh
Private Internet Access provides configuration files to use with OpenVPN. We want to download those.
cd /etc/openvpn/ sudo wget https://www.privateinternetaccess.com/openvpn/openvpn.zip sudo unzip openvpn.zip
We need to create a login script. This will provide our username and password for logging into the VPN.
sudo cp US\ East.ovpn login.ovpn sudo vim login.ovpn
Add this to the bottom:
Now we’ll edit the login config file:
sudo vim login.conf
In this file, we’ll put in the username and password provided to us by Private Internet Access.
We need to configure Transmission to use the VPN for torrent traffic. Whenever we connect to the VPN, we’re given a different IP address. We need to know what this is so we can configure Transmission to send out the traffic properly. We do this by copying the settings config file and creating a template. Then whenever the VPN connects, it updates the configuration file with the correct IP address.
cd /etc/transmission-daemon/ sudo cp settings.json settings_template.json sudo vim settings_template.json
Make sure the bind address is set to our local static IP.
Now we’ll create a file to run whenever we’re connecting to the VPN.
cd /etc/openvpn sudo vim up.sh
This file stops the transmission service, then looks in our settings template for our static IP address. Then it takes the new IP address and replaces it, then saves our settings file. Finally, it starts the transmission service.
#!/bin/sh /etc/init.d/transmission-daemon stop sed s/192.168.1.10/$4/ /etc/transmission-daemon/settings_template.json > /etc/transmission-daemon/settings.json /etc/init.d/transmission-daemon start
Finally we’ll make sure the file runs every time the VPN connects.
sudo chmod +x up.sh cd ~ sudo vim vpn.sh
Edit the file.
#!/bin/sh sudo openvpn --config /etc/openvpn/login.ovpn --script-security 2 --up /etc/openvpn/up.sh
And we’ll set permissions.
chmod +x vpn.sh
Finally, we’ll make sure the VPN connects whenever our server boots.
sudo vim /etc/rc.local
Your file should have something like this in it.
# # By default this script does nothing. /home/server/vpn.sh exit 0
You’ll probably want to reboot your server just to make sure everything starts correctly.
sudo shutdown -r now
So now, you can log into each service’s web front end using the following ports:
http://192.168.1.10:32400/manage – Plex
http://192.168.1.10:8081/home/ – Sickbeard
http://192.168.1.10:8080/ – Sabnzb
http://192.168.1.10:5050/ – Couchpotato
http://192.168.1.10:9091 – Transmission