Welcome back! Today I’m working on a project to secure my web surfing to be an anonymous as possible using a combination of a software package called “Pi-Hole” and a VPN provider.
So, let’s start at the basics: VPN and DNS
DNS, or Domain Name System, is how we access data on the web. Think of it like a pointer: When you go to facebook.com, your request goes to a DNS server which takes the website name (facebook.com) and converts it to an IP address of a server to access the website. Example:
euthonis@DESK:~$ nslookup facebook.com 172.31.1.26 Server: 172.31.1.26 Address: 172.31.1.26#53 Non-authoritative answer: Name: facebook.com Address: 31.13.67.35
Notice the 31.13.67.35. This is the IP address of Facebook’s server to connect to their website. Neat, eh? This is how most web access occurs except for rare circumstances where you would need an IP directly.
Now, VPNs.
VPNs are marketed as a way to hide your browsing and activity online, and this is true in most cases. VPN stands for “Virtual Private Network”. In a nutshell, they create a “tunnel” through which all of your web browsing goes through this encrypted tunnel so your ISP cannot see what you’re doing. This offers a great level of privacy but doesn’t prevent website tracking cookies, so there are limits to it. Most VPN services (Nord, Mullvad, TorGuard) all claim to use 0 logging on their systems; Even if ordered by a court, they do not have logs on your browsing history. Yes, this does sound a bit sketchy but even a normal user/person can benefit by not being tracked by your ISP, having your data sold to advertising companies.
So what happens if you want the ad-blocking that Pi-Hole offers along with the privacy of a VPN? You build your own DNS (Pi-Hole) server and set it up to be as anonymous as possible.
I followed the below guide for my build using Ubuntu 22.04LTS and ignoring the NetData portions (not needed for my use cases):
Create DNS-over-TLS bridge with Pi-hole, unbound and stubby on Ubuntu Server
There’s a couple configuration changes needing to be made to help us keep the Pi-Hole from logging any requests:
- In the GUI/Admin interface, go under Settings > Privacy (tab), select from the options “Anonymous Mode”. If an error occurs, go into Settings and click “Disable Query Logging”, then “Flush Logs (last 24 hours)”. This will disable all Pi-Hole logging
- Modify the file:
sudo nano /etc/unbound/unbound.conf.d/logs.conf
Edit it to look like this:
# enable query logging
server:
# If no logfile is specified, syslog is used
# logfile: "/var/log/unbound/unbound.log"
log-time-ascii: no
log-queries: no
log-replies: no
verbosity: 0
Restart the services:
sudo systemctl restart unbound stubby ; systemctl status unbound stubby -l
With these options set, there is no longer any logging on the server.
For the final part of all of this, a lot of VPN providers allow custom DNS servers to be used. Take the IP address of your DNS server and enter it into the custom DNS server of the VPN and connect. You should be able to use the internet over the VPN as before, but now you have your own controlled adblocking via Pi-Hole and the security of knowing your server does not keep logs or any history. You should, assuming your VPN is trustworthy, be essentially invisible on the internet now.
I hope this write up was helpful! I’ve been tinkering with these projects for some time off and on.
One last tip: If you find a website is blocked improperly from Pi-Hole, you may need to enable logging again (reversing the items from Step 1, above) to whitelist the problem domain. Don’t forget to turn logging back off after!