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 ~
sudo apt-get install network-manager
sudo sh

Private Internet Access provides configuration files to use with OpenVPN. We want to download those.

cd /etc/openvpn/
sudo wget
sudo unzip

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:

auth-user-pass /etc/openvpn/login.conf

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.


Configuring Transmission

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.

"bind-address-ipv4": "",

Now we’ll create a file to run whenever we’re connecting to the VPN.

cd /etc/openvpn
sudo vim

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.


/etc/init.d/transmission-daemon stop
sed s/$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
cd ~
sudo vim

Edit the file.

sudo openvpn --config /etc/openvpn/login.ovpn --script-security 2 --up /etc/openvpn/

And we’ll set permissions.

chmod +x

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.
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: – Plex – Sickbeard – Sabnzb – Couchpotato – Transmission

4 Responses to “Set Up a Streaming Media Server – Pt. 8 – Set up VPN”

  1. CdrJameson says:

    Brilliant guide. I managed to follow it all the way through and now have a a separate VM Media server with Usenet, Torrents, VPN and CP and SB all set up. just need to figure out how to use it all. I have connected my TV to the Plex server and it works flawlessly.

    Just need to figure out how to use it most effectively. Fancy writing a guide for that?

  2. en0ch says:

    I’ve thought about writing a followup post with some tips and tricks for any weird issues that come up, like missing episodes, failed downloads, Plex server settings, etc…

    I also had to increase the size of the VM hard drive, but I didn’t document that well so I doubt I’ll be able to write about it again (unless I have to increase it again and figure out how I did it all over again).

  3. Rick says:

    How can I make sure and test that Transmission is using my PIA openvpn connection?

  4. nekkidtruth says:

    Thank you so much for this guide! I currently have all of this set up on my Windows desktop and have been wanting to move to a virtual Linux environment. Thank you for putting it all in one place :)

Leave a Reply to nekkidtruth Cancel reply