VPN + Ad blocking on the go
Using WireGuard VPN and Pi hole for better, safer, private navigation.
Some time ago I wrote about Pi hole, an awesome project that helps you leverage your Raspberry Pi to create a black hole for ad servers and trackers. So, whenever I'm at home, I don't see ads... even on my phone!
But what if I wanted to also have that when I leave the house... so I'm not in my home network / wifi? And what if I want to use some wifi somewhere else and don't want people to be able to look into my traffic?
Luckily, we can fix it all together by creating a 🔐 WireGuard VPN 🔐 server in the same Raspberry Pi we previously used for Pi hole as a server.
Creating a new WireGuard VPN server in your Pi
We will use PiVPN for that! Installing it is quite simple. Just run the following and follow the instructions (I swear, they are quite simple!). Make sure to select WireGuard when asked whether to use WireGuard or OpenVPN.
curl -L https://install.pivpn.io | bash
The script will detect that a Pi hole is running in the same machine as the VPN server, and it will ask you if you want to use it to filter ads and trackers. Say yes.
After installing everything, it will ask you to reset your Pi, so do that. When it's back online, make sure to run:
sudo pivpn add
With this you will be able to create a new VPN profile. You can then create a QR code for it, which you will be able to use in your WireGuard app from the Play Store or the App Store.
pivpn -qr <your profile name>
Just snap a pic of the QR with the app, and it'll be configured. Make sure you take a picture of it for safekeeping, maybe add it to a secure note in your 1Password, Lastpass or somewhere else you can trust.
Make sure that you have your router redirect port 51820 (or the new one if you changed it in the configuration) to your Raspberry Pi, and you are good to go!
Automatically using the VPN when leaving the house with Tasker
So, if you have an Android phone, there is this little app called Tasker that allows you to do pretty much everything with your phone.
You will need to create a new Task that you could call VPN Off action which will look like this:
To get to that function, you can create a new action of type Tasker function, and on it you press the search button in Function, and look for WireGuard Set Tunnel towards the end of the list. You'll need to say that you want to add an action for when it's NOT UP.
You will then also need to create another Task, now called VPN On. You can follow the same steps, but just say that you want to do it when the tunnel is UP.
You can refer to this video to see how to do these actions easily.
Then you will need to create a Profile for Status > Wifi Connected. For action you will give it VPN Off. You can then long press on it, add an Exit Task, and select VPN On.
The end result will look like this.
With this, whenever you leave your home wifi, you will be automatically connected to the VPN. When coming back home, you'll be disconnected.
And that's it! Enjoy your safe and ad free tracker free navigation!