• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Miguel Ángel Antolín Bermúdez

Personal portfolio & Blog

  • Home
  • Blog & posts
You are here: Home / Engineering / how to / Block ads anywhere with Pi-hole and a VPN

Engineering, how to, Networking, Raspberry Pi, Security, Self-hosting / 27th January 2018

Block ads anywhere with Pi-hole and a VPN

Ads follow you everywhere — laptop, phone, smart TV. Pi-hole is a DNS sinkhole that blocks ad-serving and tracking domains at the network level, so every device benefits without needing a browser extension. Combine it with OpenVPN and you route your phone’s traffic through your home network while on mobile data, blocking ads wherever you go. This guide walks through setting up both services and wiring them together.

How it works

When a device resolves a hostname, Pi-hole checks it against a blocklist of known ad and tracking domains. Blocked queries never leave your network — they get a null response instantly. OpenVPN creates an encrypted tunnel from your remote device back to your home Pi, so all DNS queries go through Pi-hole regardless of where you are.

Step 1 — Install OpenVPN

wget https://git.io/vpn -O openvpn-install.sh
sudo chmod a+x openvpn-install.sh
sudo ./openvpn-install.sh

Enter your Pi’s local IP when prompted. When asked which DNS to use, choose option 1 (current system resolvers) — you will point it at Pi-hole in the next step. Accept the remaining defaults.

Step 2 — Install Pi-hole

curl -sSL https://install.pi-hole.net | bash

When asked which network interface to listen on, select tun0 — the virtual interface created by OpenVPN. If you select your physical interface (eth0) instead, Pi-hole will not receive DNS queries from VPN clients. Accept all other defaults.

Step 3 — Point OpenVPN at Pi-hole

Find the tun0 IP address (typically 10.8.0.1):

ip addr show tun0
sudo nano /etc/openvpn/server.conf

Update the DNS push directive:

push "dhcp-option DNS 10.8.0.1"
sudo systemctl restart openvpn

Step 4 — Create a VPN client profile

sudo ./openvpn-install.sh

Select “Add a new client”, give it a name, and a .ovpn file will be created in your home directory. Import it into an OpenVPN client app on your device. Once connected, all DNS traffic flows through Pi-hole and ads are blocked everywhere — on every device, on every network.

For more on Pi-hole’s features and blocklist management, visit pi-hole.net. More Raspberry Pi tutorials on the blog.

Filed Under: Engineering, how to, Networking, Raspberry Pi, Security, Self-hosting Tagged With: adblocker, Pi-hole, pi-hole,vpn,ad-blocking,raspberry-pi,networking,dns,privacy,openvpn, Raspberry, VPN

Footer

Find me at

  • GitHub
  • LinkedIn

Recent Posts

  • Git for solo developers: the workflow that actually works
  • Self-hosting Vaultwarden on a VPS: your own Bitwarden server
  • Docker on a Raspberry Pi: running containers on ARM
  • WireGuard VPN on a Raspberry Pi: replace OpenVPN in 15 minutes
  • Claude Code on Mac: the complete setup guide

© 2026 · Made with ❤️ in Seville