Technology Encyclopedia Home >Set Up a Personal VPN with Pi-hole Ad Blocking on a VPS — Private Browsing with Network-Wide Ad Filtering

Set Up a Personal VPN with Pi-hole Ad Blocking on a VPS — Private Browsing with Network-Wide Ad Filtering

I travel frequently and use public WiFi often. Two things bother me about that: the lack of privacy and the ads. This guide solves both: WireGuard routes my traffic through a cloud server for privacy, and Pi-hole running on the same server filters ads and trackers at the DNS level for every device on the VPN.

The result: all my devices — laptop, phone, tablet — route through my VPN, ads are blocked before they even load, and trackers can't build a profile across my browsing. One cloud server handles everything.

I run this on Tencent Cloud Lighthouse. The entry-level plan handles both WireGuard and Pi-hole easily — they're both lightweight. The key choice for a VPN+Pi-hole setup is region: pick a data center that matches where you want your traffic to appear to originate. Lighthouse has data centers in North America, Europe, Singapore, Tokyo, and more. The fixed bandwidth allowance also means routing all your browsing traffic through the VPN doesn't generate per-GB charges — predictable costs regardless of how much you browse.


Table of Contents

  1. How This Setup Works
  2. What You Need
  3. Part 1: Install WireGuard VPN
  4. Part 2: Install Pi-hole
  5. Part 3: Configure Pi-hole as the VPN's DNS
  6. Part 4: Add Clients to the VPN
  7. Part 5: Configure Mobile Devices
  8. Part 6: Customizing Pi-hole Block Lists
  9. The Thing That Tripped Me Up
  10. Troubleshooting
  11. Summary

  • Key Takeaways
  • Use the appropriate Lighthouse application image to skip manual installation steps where available
  • Lighthouse snapshots provide one-click full-server backup before major changes
  • OrcaTerm browser terminal lets you manage the server from any device
  • CBS cloud disk expansion handles growing storage needs without server migration
  • Console-level firewall + UFW = two independent protection layers

How This Setup Works {#how-it-works}

Your Device → WireGuard tunnel → Cloud Server → Internet
                                      ↓
                                   Pi-hole
                                 (DNS filter)
                                      ↓
                              Blocked ads/trackers
                              never reach your device

When you're connected to the VPN:

  • All DNS queries go through Pi-hole on your server
  • Pi-hole blocks ad domains, tracker domains, malware domains before the DNS response is returned
  • Allowed domains resolve normally
  • Your traffic exits from your cloud server's IP

What You Need {#prerequisites}

Requirement Details
Server Ubuntu 22.04, 1 GB+ RAM
Open ports 51820/udp (WireGuard), 53/tcp+udp (DNS, internal only)
Domain Optional — not needed for basic setup
Devices to connect Any — WireGuard runs on all major platforms

Part 1: Install WireGuard VPN {#part-1}

1.1 — Install WireGuard and the Easy Setup Script

sudo apt update
sudo apt install -y wireguard

# Install the easy-setup script
curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh
chmod +x wireguard-install.sh
sudo ./wireguard-install.sh

Follow the prompts:

  • Server's public IP: Your Lighthouse instance's public IP
  • Port: 51820 (default)
  • DNS: We'll change this to Pi-hole's IP later — for now, enter 1.1.1.1
  • Client name: Give your first device a name (e.g., laptop)

The script generates:

  • Server keys and config at /etc/wireguard/wg0.conf
  • Client config at ~/laptop.conf (or wherever it saves it)

1.2 — Enable and Start WireGuard

sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
sudo systemctl status wg-quick@wg0

1.3 — Open the WireGuard Port

sudo ufw allow 51820/udp
sudo ufw reload

Also open port 51820/udp in your Lighthouse console firewall.

1.4 — Enable IP Forwarding

echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl -p /etc/sysctl.d/99-wireguard.conf

Part 2: Install Pi-hole {#part-2}

2.1 — Run the Pi-hole Installer

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

During installation, choose:

  • Interface: wg0 (WireGuard interface) — if it asks which interface to listen on
  • Upstream DNS: Select any (we can change this later)
  • Block lists: Keep defaults
  • Admin web interface: Yes
  • Web server (lighttpd): Yes
  • Query logging: Yes (useful for debugging)

At the end, note the admin password printed. You can also reset it:

pihole -a -p newpassword

2.2 — Note Pi-hole's Local IP

Pi-hole listens on the server's local IP. The WireGuard server assigns itself 10.0.0.1 by default.

ip addr show wg0
# Look for: inet 10.0.0.1/24

Pi-hole will be reachable at 10.0.0.1 from VPN clients.

2.3 — Configure Pi-hole to Listen on WireGuard Interface

In Pi-hole admin UI (http://10.0.0.1/admin from within the VPN):

  1. Go to Settings → DNS
  2. Under Interface settings, select Listen on all interfaces or specifically select wg0
  3. Click Save

Or via command line:

sudo nano /etc/pihole/pihole-FTL.conf

Add:

REPLY_ADDR4=10.0.0.1

Restart Pi-hole:

pihole restartdns

Part 3: Configure Pi-hole as the VPN's DNS {#part-3}

Update the WireGuard server config to use Pi-hole for DNS.

3.1 — Edit the WireGuard Server Config

sudo nano /etc/wireguard/wg0.conf

In the [Interface] section, there should be a PostUp and PreDown rule. Make sure the server config doesn't redirect DNS — it's handled at the client level.

3.2 — Update Client DNS to Point to Pi-hole

Edit existing client configs and any new client configs to use 10.0.0.1 as DNS:

Open the client config file (e.g., ~/laptop.conf):

sudo nano ~/laptop.conf

Find the [Peer] or [Interface] section with DNS:

[Interface]
PrivateKey = ...
Address = 10.0.0.2/24
DNS = 10.0.0.1        # ← Change this to Pi-hole's IP

For new clients, the setup script generates configs — edit them before distributing to devices.

3.3 — Configure Pi-hole Upstream DNS

In Pi-hole admin → Settings → DNS:

Upstream DNS servers (what Pi-hole uses after filtering):

  • Select Cloudflare (1.1.1.1) for speed and privacy
  • Or use Google (8.8.8.8)

Uncheck any others to use only one provider.


Part 4: Add Clients to the VPN {#part-4}

Add a New Device

Run the setup script again:

sudo ./wireguard-install.sh

Choose "Add a new client", give it a name. The script creates a new config file and a QR code.

Or manually add a peer:

# On server
wg genkey | tee /tmp/client_private.key | wg pubkey > /tmp/client_public.key

# Add to server config
sudo nano /etc/wireguard/wg0.conf

Add at the end:

[Peer]
PublicKey = CLIENT_PUBLIC_KEY_HERE
AllowedIPs = 10.0.0.3/32

Restart WireGuard:

sudo wg-quick down wg0 && sudo wg-quick up wg0

Create the client config file:

[Interface]
PrivateKey = CLIENT_PRIVATE_KEY_HERE
Address = 10.0.0.3/24
DNS = 10.0.0.1

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = YOUR_SERVER_IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Part 5: Configure Mobile Devices {#part-5}

iOS and Android

  1. Install the WireGuard app (iOS App Store / Google Play)
  2. On the server, generate a QR code for the client config:
# Show QR code for a client config
sudo qrencode -t ansiutf8 < ~/laptop.conf

Or if using the install script, it generates a QR code automatically.

  1. In the WireGuard app: + → Scan from QR code
  2. Scan the QR code

macOS and Windows

Download the WireGuard client from wireguard.com.

Import the .conf file (copy it to your device via SCP or paste the contents):

# Copy config to local machine
scp ubuntu@YOUR_SERVER_IP:~/laptop.conf ~/Downloads/laptop.conf

Part 6: Customizing Pi-hole Block Lists {#part-6}

Default Block Lists

Pi-hole comes with the default Steven Black list (~100k+ domains). This blocks most major ad networks.

Add More Block Lists

In Pi-hole admin → Group Management → Adlists → Add new adlist:

Popular additions:

List Name URL Blocks
OISD Full https://big.oisd.nl Ads + trackers + malware
Hagezi Pro https://raw.githubusercontent.com/hagezi/dns-blocklists/main/domains/pro.txt Comprehensive
Developer Dan https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt Ads + tracking

After adding, run:

pihole -g

This downloads and updates all block lists.

Whitelist Domains

If Pi-hole blocks something you need:

# Whitelist a domain
pihole -w yourdomain.com

# Or via admin UI: Whitelist → Add

View Query Log

In Pi-hole admin → Query Log: see every DNS query in real time. This is useful for identifying what's being blocked and what's generating traffic.


The Thing That Tripped Me Up {#gotcha}

After setting everything up, Pi-hole was working when I tested from the server itself, but connected VPN clients weren't getting ad filtering — DNS queries were going through, just not being filtered.

The issue: WireGuard clients were using DNS = 10.0.0.1 in their config (Pi-hole's IP on the WireGuard network), but Pi-hole was only listening on eth0 (the server's main interface), not on wg0.

Two symptoms:

  1. DNS worked (so WireGuard tunnel was fine)
  2. But ads weren't blocked (Pi-hole wasn't intercepting the queries)

The fix:

sudo nano /etc/pihole/pihole-FTL.conf

Add:

LISTEN_LOCALONLY=no

Then in the Pi-hole admin under Settings → DNS → Interface settings: choose "Permit all origins" instead of "Listen only on interface eth0".

After pihole restartdns, VPN clients' queries started flowing through Pi-hole.

Security note: "Permit all origins" means Pi-hole listens on all interfaces. Since port 53 is not exposed in UFW/Lighthouse firewall (only port 51820/udp for WireGuard is open), external access to Pi-hole's DNS is blocked at the network level. VPN clients reach it through the WireGuard tunnel.


Troubleshooting {#troubleshooting}

Issue Likely Cause Fix
VPN connects but no internet IP forwarding not enabled sysctl net.ipv4.ip_forward=1
DNS not filtering ads Pi-hole not on wg0 Set "Permit all origins" in Pi-hole DNS settings
Can't reach Pi-hole admin Wrong IP Admin is at 10.0.0.1/admin when connected to VPN
All DNS failing Pi-hole upstream issue Check Pi-hole upstream DNS in settings
Client disconnects frequently No keepalive Add PersistentKeepalive = 25 to client config
Too many false positives Overly aggressive block list Remove stricter lists; whitelist needed domains
Pi-hole stats show no queries Wrong DNS IP in client Verify client config has DNS = 10.0.0.1

Summary {#verdict}

What you built:

  • WireGuard VPN running on your cloud server
  • Pi-hole DNS filtering blocking ads and trackers network-wide
  • All VPN-connected devices automatically get ad blocking
  • Multiple device support: laptop, phone, tablet, router
  • QR code setup for easy mobile device onboarding
  • Customizable block lists for different filtering levels

The combined setup blocks 20-40% of DNS queries on average (mostly ads and trackers that never load). Browsing feels noticeably cleaner, and pages load faster without fetching ad content.

Frequently Asked Questions {#faq}

How many simultaneous connections can a VPN server on a VPS handle?
For personal or small team use, a VPS handles 10–30 simultaneous VPN connections comfortably. Bandwidth is usually the limiting factor, not CPU or RAM.

Will a self-hosted VPN make all my traffic private?
Your traffic is encrypted between your device and the VPN server. After the VPN server, traffic goes to its destination normally. The VPN protects against network-level eavesdropping but doesn't make you anonymous on the public internet.

What region should I choose for my VPN server?
Choose based on your use case: for low latency, pick the region closest to you. For a specific exit IP location (e.g., to access a region-specific service), pick accordingly. Lighthouse has data centers in North America, Europe, and Asia-Pacific.

Is WireGuard more secure than OpenVPN?
Both are considered secure. WireGuard's codebase is substantially smaller (4,000 lines vs 70,000+), making it easier to audit. OpenVPN has a longer track record. For most users, WireGuard is the better choice for new deployments.

Can I use the VPN on mobile devices?
Yes — WireGuard and OpenVPN both have official mobile apps for iOS and Android. Client configuration is imported via QR code (WireGuard) or .ovpn file (OpenVPN).

👉 Get started with Tencent Cloud Lighthouse
👉 View current pricing and launch promotions
👉 Explore all active deals and offers