Secure access to Tvheadend server

A project log for Bypassing TV broadcasting restrictions

A compact Tvheadend server based on a RPi3 to bypass geographical restrictions of TV broadcasting

SolenoidSolenoid 04/27/2016 at 05:350 Comments

Internet security is a hot topic nowadays, having computers exposed to the internet (opened ports) is a very real risk and you wouldn't believe the number of bots that are scanning through all the IP addresses in hope of finding an ill-configured system or simply brute forcing everything.

I recently had an experience where one of the computers I managed, which had an exposed port 22 (SSH), was being brute forced from a Chinese IP addresses. Fortunately SSH was not enabled for the the root account, which it tried to break. However sooner or later on unchecked systems a robot will succeed and compromise the network.

This is why I'm writing about a simple way to set up a truly robust connection, as the Tvheadend server in this project obviously needs remote access.

Enter OpenVPN: an open, free, robust and easy to setup virtual private network software. It has a slight learning curve which might be discouraging at first, but this tutorial here explains how to set it up for the current use case, actually it's surprisingly easy and painless (as long as you use tunnelling mode and not ethernet bridging)

The VPN provides an encrypted connection, it does not require any configuration of the remote router, which is really nice as the Tvheadend server might be left at a friends or relatives place and changing their router settings is not always possible/allowed.

The network is set up as follows:

This is the network setup I'm going for here. The media center ( I'm using, based on Kodi, will be able to access the Tvheadend server via the IP address, through the OpenVPN server on The red arrow indicates the virtual connection, the true physical connection is represented by the black arrows.

One could also set up the OpenVPN server on the media center computer, however I want to run a couple other services on the Raspberry Pi 1 which I don't want on the media center itself (Pi-Hole, OwnCloud...).

Installing OpenVPN

DietPi has pre-configured packages that one can install by simply checking a box, it is super useful in this case.

Simply call:


Which opens the software installation process:

Select "Software Optimized", scroll down until you see "OpenVPN", hit the space-bar to select it and follow the instructions to install it. Do the same for the server and client.

Generating certificates

Configuring the OpenVPN server is a fairly straight forward procedure, you don't need to understand everything (I sure didn't), some certificates (read: impossible-to-guess-super-long-passwords) simply need to be generated and copied from the server to the client.

I followed the instructions on the official OpenVPN how-to tutorial.

First go to /etc/openvpn/easy-rsa/ where all the tools for certificate creation are located. Execute the following commands in order and hit enter or reply with "y" whenever it asks for something:

. ./vars
./build-key-server server
./build-key client_tvheadend
./build-key client_osmc

It created some files under /etc/openvpn/easy-rsa/keys/ which need to be copied to /etc/openvpn/ on the server and client computers.

Configuring OpenVPN server

Copy the following files to /etc/openvpn/ on the server:

Create the configuration file for the server, named server.conf in /etc/openvpn/. This is the main file that needs some custom setup and it is the only thing that differentiates the server from the client. I used the template provided by OpenVPN for the server.

To allow the clients to access each other modify the following lines in server.conf:

  1. Uncomment "client-to-client"
  2. Save the configuration
  3. Reboot

Since the client connects to the OpenVPN server over the internet the local router should properly forward the OpenVPN port. I left the default 1194 UDP port and forwarded it in the router to the OpenVPN server computer (for me it was

Configuring Tvheadend client

Copy the following files to /etc/openvpn/ on the Tvheadend client:

Create the configuration file for the client, named client_tvheadend.conf in /etc/openvpn/. Use the template provided by OpenVPN for the client.

  1. Configure "remote...", for me it was "remote <your OpenVPN server IP/URL> 1194"
  2. Change "cert..." to "cert client_tvheadend.crt"
  3. Change "key..." to "key client_tvheadend.key"
  4. Reboot

Configuring the media center client

Just like the Tvheadend client copy the following files to /etc/openvpn/ on the media center client:

Create the configuration file just as before, add the proper modifications as above and reboot.

Establishing connection

If everything was configured properly the VPN should now be running and the clients connected, the server and clients can see each other on the 10.8.0.x subnet. The server shows the connected clients in the /etc/openvpn/openvpn-status.log file.

End notes