All Articles

Using OpenVPN with Pi-hole on a VPS

Last year during Black Friday sales, I paid USD7/year for a VPS (over at LEB). For that price, I wasn’t expecting it to be fast but I also wasn’t expecting that it would go down for hours on end, enjoying an uptime of about 98%. Clearly, using it as a host even for non-critical apps (like this blog) is out of question so it’s time to find a suitable use case where 98% of the time, it works every time is good enough.

OpenVPN

Speedtest results, 30mbps download, 4mbps upload

Turns out the VPS has pretty decent speed, and because it offers 1.5TB of monthly data transfer, it is perfect for a VPN. Being down 1-2% of the time isn’t really a deal breaker (as long as I am not performing any critical tasks like monetary transactions).

Server

There are several VPN solutions to choose from but I decided to go with OpenVPN using this script (on a cleanly installed machine) for its ease of installation. Just follow the onscreen instruction and you will end up with a reasonably secure installation of VPN server.

Alternatively you can follow the installation instruction at Pi-hole documentation which uses the original OpenVPN installation script that the one I recommended above was forked from.

If you have a generous monthly data transfer quota, you might also want to create a few more profiles for friends and family like I did!

Client

Now, you need to install the client in order to connect to your server (see below for what I use). After you have installed them, you should be able to use your configured server by importing the .ovpn file that was created on the server during installation.

The clients I use:

Pi-Hole

Normally I would be happy at this point and call it a day but since the VPS is pretty beefy (with a 1GB RAM), I wanted to see what else I could use it for.

Googling for some recommendations, I found out about Pi-hole. It blocks ads/privacy trackers at the DNS level and although it was originally designed to be used with Raspberry Pi devices, it has since evolved to be used with VPN, which would be my use case.

The installation (instructions provided on its website) should be quite straightforward (however do read about its warning against directly piping to shell during installation) if you are used to installing software using the command-line.

The default configuration should give you enough and because everyone has different requirement, if you are looking to block more, you should start here. Remember to start adding them slowly to see whether your usual sites are affected, and in some cases you might simply need to just add them to whitelist to continue using them.

There is no client installation necessary to use Pi-Hole because you will be using it through the OpenVPN you installed earlier.However, Pi-Hole has an web admin interface that you can visit to do your configuration which looks something like:

Pi-Hole web admin UI

Results

Now with all that done, it is time to see what benefits the setup brings.

Lesser data transferred

Here are some numbers about the transfer size measured at page load (without any scrolling to avoid lazy-loading kicking in).

Without Pi-Hole With Pi-Hole Savings in data
The Verge 2.5MB 1.1MB 56%
USA Today 5.3MB 2.5MB 52%

Data above are just an example at time of writing this post, actual savings really depends on the sites you visit and the kind of ads/trackers they serve. And although this was measured on a desktop browser, one should expect similar saving on mobile browsers as well (especially for me since I am using iOS Firefox and cannot install any ad-blockers beside the built-in tracking protection that comes with Firefox).

Better battery life

In theory it should reduce the battery drain of your devices since your browser is processing lesser scripts, but in my experience, the use of OpenVPN on iOS itself regularly takes up 25% of the battery usage (as seen in the “Battery” section in Settings) so YMMV. Might be worth it for a greater good?

Better security on public WiFi

In theory, it’s safer. But in practice, there are many factors at play. So once again, YMMV.

Ads- and tracker-free

At the end of the day, if you are concerned about privacy online, this will be the biggest gain.

With this, I turned my unreliable VPS into one I now use regularly! Hopefully this post introduces some possibilities for your (idle) VPS that would make it actually useful!