How to Set Up a DNS-Based Ad Blocker (Pi-hole) on a VPS

Pi-hole blocks ads and trackers network-wide by filtering DNS requests before they reach known ad/tracker domains — running it on a VPS gives you network-wide ad blocking accessible from anywhere, not just your local network.

How DNS-Based Ad Blocking Works

Pi-hole acts as your DNS resolver — when a device requests a domain known to serve ads/trackers, Pi-hole returns a blocked response instead of resolving it, preventing the ad/tracker content from ever loading, network-wide, without needing per-device browser extensions.

Why Run Pi-hole on a VPS Instead of Locally

  • Accessible from anywhere (mobile devices on cellular data, not just your home WiFi)
  • Always-on, unlike a home device that might be powered off
  • Doesn't consume resources on your home network hardware

Prerequisites

  • Ubuntu 22.04/24.04 VPS: 1 vCPU, 1 GB RAM (genuinely lightweight)

Step 1 — Install Pi-hole

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

Follow the interactive installer — select your upstream DNS provider and confirm installation settings.

Step 2 — Access the Web Admin Interface

http://YOUR_SERVER_IP/admin

The installer displays your admin password at the end of installation — note it, or reset it if needed:

sudo pihole -a -p

Step 3 — Allow DNS Traffic Through the Firewall

sudo ufw allow 53/tcp
sudo ufw allow 53/udp

Step 4 — Configure Your Devices to Use Pi-hole as DNS

On each device (or your router, for network-wide coverage), set the DNS server to your VPS's IP address — the exact configuration steps vary by device/OS.

Step 5 — Secure DNS Access to Trusted Clients Only

sudo ufw delete allow 53/tcp
sudo ufw delete allow 53/udp
sudo ufw allow from YOUR_TRUSTED_IP to any port 53

Important: an open DNS resolver reachable by anyone can be abused for DNS amplification attacks — restrict access specifically to your own known devices/IPs, not left open to the entire internet.

Using Pi-hole with a VPN for Mobile Coverage

For genuinely reliable mobile device coverage (where your IP changes constantly), combine Pi-hole with a VPN (see How to Set Up a VPN Server with WireGuard) — route mobile traffic through the VPN, then configure the VPN to use Pi-hole for DNS, avoiding the open-resolver security concern entirely.

Adding Custom Blocklists

Pi-hole supports adding additional blocklist sources beyond the defaults, under Group Management → Adlists in the web interface — various community-maintained lists exist for different blocking focuses (ads, trackers, malware domains).

Whitelisting Domains That Get Incorrectly Blocked

Occasionally a legitimate domain gets caught by a blocklist — use the web interface's whitelist function to override this for specific domains you've verified are safe and needed.

Common Errors

DNS resolution fails entirely after switching to Pi-hole — verify Pi-hole's service is actually running (sudo systemctl status pihole-FTL) and that firewall rules genuinely allow your device's IP to reach port 53.

Continue Reading

Browse more articles in Networking & DNS.

  • pi-hole vps, dns ad blocker, network wide ad blocking, pi-hole installation
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

DNS Fundamentals: A, AAAA, CNAME, MX, TXT & NS Records Explained

DNS translates human-readable domain names into the information servers actually need — IP...

How to Point a Domain to Your VPS (A/AAAA Records)

Before your website is reachable at yourdomain.com instead of a raw IP address, you need to...

How to Configure MX Records for Email Delivery

MX (Mail Exchange) records tell the internet which servers handle incoming email for your domain....

How to Use CNAME Records Correctly

CNAME records let you alias one domain name to another, but they come with important restrictions...

How to Configure a Static IP on a Linux VPS

Most VPS providers assign a static (unchanging) IP address by default, but understanding how...