Guide: Setup WireGuard VPN + Pi-hole (Network-Wide Ad Blocker) on Linux
Want to browse the internet on your phone or laptop with absolutely zero ads, while staying completely secure on public Wi-Fi? This guide will show you how to install a WireGuard VPN server and route its traffic directly through a Pi-hole DNS server on the same Linux VPS.
Prerequisites
Step 1: Install Pi-hole via Official Script
First, we install Pi-hole. Run the automated installer script on your server:
During the blue configuration screens:
Step 2: Install and Configure WireGuard
Instead of manual setups, we will use a highly optimized script that allows us to easily point the VPN's DNS directly to our new Pi-hole server:
Important choices during setup:
Step 3: Allow Pi-hole to Accept VPN Traffic
By default, Pi-hole only listens to local queries. We need to tell it to accept requests coming from our WireGuard tunnel interface:
Step 4: Connect Your Client Device
The WireGuard script generated a QR code in your terminal.
Drop a comment below if some ads are still slipping through your connection!
Want to browse the internet on your phone or laptop with absolutely zero ads, while staying completely secure on public Wi-Fi? This guide will show you how to install a WireGuard VPN server and route its traffic directly through a Pi-hole DNS server on the same Linux VPS.
Prerequisites
- A clean Ubuntu 22.04 / 24.04 VPS
- Root or sudo privileges
- Ports 51820/udp (WireGuard) and 80/tcp (Pi-hole Web UI) open
Step 1: Install Pi-hole via Official Script
First, we install Pi-hole. Run the automated installer script on your server:
Code:
curl -sSL https://install.pi-hole.net | bash
- Choose your primary network interface (e.g., eth0).
- Select any upstream DNS provider (Cloudflare 1.1.1.1 or Google 8.8.8.8 are great options).
- Keep the default blocklists turned ON.
- Enable the Web Admin Interface.
- At the very end, write down the admin login password displayed on the screen.
Step 2: Install and Configure WireGuard
Instead of manual setups, we will use a highly optimized script that allows us to easily point the VPN's DNS directly to our new Pi-hole server:
Code:
wget https://git.io/wireguard -O wireguard-install.sh chmod +x wireguard-install.sh sudo ./wireguard-install.sh
- Port: Keep default 51820.
- Client Name: Enter phone or laptop.
- DNS Server: Choose Custom and enter: 10.0.0.1 (or your Pi-hole internal server IP).
Step 3: Allow Pi-hole to Accept VPN Traffic
By default, Pi-hole only listens to local queries. We need to tell it to accept requests coming from our WireGuard tunnel interface:
- Open your web browser and go to: http://your_server_ip/admin
- Log in with the password from Step 1.
- Go to Settings -> DNS tab.
- Scroll down to Interface settings and select: "Permit all origins" (This is safe because your server firewall protects it).
- Click Save at the bottom.
Step 4: Connect Your Client Device
The WireGuard script generated a QR code in your terminal.
- Download the official WireGuard app on your iPhone or Android.
- Click the + icon -> Scan QR code.
- Turn the VPN on, and enjoy an entirely ad-free web experience across all apps and browsers!
Drop a comment below if some ads are still slipping through your connection!