In this article, we talk about using a virtual private server (VPS) to host a Pi-Hole instance which is usable through a VPN connected to the VPS. If you wanna skip all the explanation and just go straight to how to do it, click here or use the table of contents to navigate.
This is honestly not new knowledge in any way, shape or form. I know there are a lot of tutorials on how to do these things (making a VPN, making a Pi-Hole) individually, but I'm not seeing many that does both and is easily understandable by a layman like me.
The objective of writing this down for me is to 1. save you some time from reading 21 articles separately and 2. consolidate ideas on how to make this better, in case I'm doing anything wrong.
- Using a VPN reroutes your traffic to a specific location. (gross oversimplification)
- Using Pi-Hole blocks outgoing traffic according to a list you supply.
- A Pi-Hole server lives on a specific device.
- Using a VPN, the limitation of a Pi-Hole only being on a device you can't bring out can be eliminated.
- PiVPN (Wireguard) - Chosen because of the simple installation and fast speed.
- DigitalOcean Droplet ($5) - Chosen because of the 1,000GB connection pool bandwidth, also has balanced website complicatedness. Alternatively, you can choose to do this combination on a home device too, you'll connect to your own home network, that's all. I wanted to have the ability to access certain location-blocked sites. The destination of the VPN tunnel will depend on where you set up your server to be. In theory, AWS or some other VPS provider should also follow approximately the same steps. I've heard that Oracle Cloud free tier is also pretty good in value.
- Make a DO account.
- Make a DO droplet. I used Ubuntu on a basic plan ($5 per month).
- After the VPS is deployed, create a floating IP and assign to your Droplet. (This serves as a static IP sort of thing)
- Then we add a custom firewall rule. We open up access for a UDP connection from port 51820. This port is used for your device to tunnel into your Droplet.
- Connect to your Droplet through SSH.
curl -L https://install.pivpn.io | bashto install PiVPN. Just follow the steps, shouldn't be too overcomplicated. Make sure that the VPN protocol chosen is Wireguard.
- If you do
ipconfig, your device should now also include
ip addr show wg0to see what IP address is
wg0using. (Take a screenshot/Note it down)
ip route show | grep defaultto see which IP address is used to route network requests to the Internet. (Take a screenshot/Note it down)
curl -sSL https://install.pi-hole.net | bashto install Pi-Hole.
- When prompted about IP address and Gateway, use the one in Step 7 for IP address (keep the default port [the number after the slash]) and the IP address in Step 8 for gateway.
- Complete the installation process.
- You can now add devices to connect through PiVPN. Use
pivpnfor a list of commands or just visit the project page for more help on the matter.