How to Self-Host Pi-hole on a VPS
Run Pi-hole on an Ubuntu 24.04 VPS behind a WireGuard tunnel, why plain DNS on a shared IPv4 port block does not work, and how to back up and update it.
Pi-hole is a DNS server that answers lookups for ad, tracker and malware domains with nothing, so they never load on devices that use it. It was built for a home network, and a server in a data centre changes what it can do. This guide explains what works on a VeloxaHost server and what does not, then installs Pi-hole on Ubuntu 24.04 behind a WireGuard tunnel, the setup from Pi-hole's own documentation.
Prefer one click? Deploy Pi-hole from the VeloxaHost marketplace and skip the manual steps; this guide is for when you want to run every command yourself.
What you need
- A VeloxaHost server with the Ubuntu 24.04 LTS image. You get root, over SSH or in the browser terminal on the server's page.
- The WireGuard app on each phone or laptop you want to filter.
What works and what does not. Pi-hole answers DNS on port 53. Every VeloxaHost server gets a block of ports on a shared IPv4 address, and the first port forwards to SSH. You can forward another port of the block to 53, but the public side is a high port such as 20003. Phones, Windows, macOS and most home routers accept a DNS server address and nothing else; there is no field for a port. Plain DNS over the shared address therefore does not reach the devices you want to filter.
A dedicated IPv4 (a paid add-on; the console shows the current price) does give you port 53, but it brings a different problem. Pi-hole's default listening mode, "Allow only local requests", ignores your home, because your home is not on one of the server's subnets. Switching to "Permit all origins" turns the server into an open resolver, which Pi-hole's docs warn can be used in DNS amplification attacks against others. A firewall rule for your home address helps only while that address stays the same, and most home connections change theirs. We do not recommend public DNS on port 53.
What does work is a tunnel. WireGuard runs on a UDP port you forward from your block, your devices connect to it, and Pi-hole answers them on the tunnel address 10.100.0.1. To Pi-hole the tunnel is a local subnet, so the safe default mode serves your devices and nobody else. Filtering every device at home this way needs a router that runs a WireGuard client.
Pi-hole needs 512 MB of RAM and 2 GB of free disk, 4 GB recommended. A Veloxa Nano (1 vCPU, 1 GB RAM, 25 GB disk) at $4 a month, billed at $0.01 an hour and capped at the monthly price, is plenty.
Install Pi-hole
Download the installer, read it if you like, and run it. This is the second method on Pi-hole's install page.
wget -O basic-install.sh https://install.pi-hole.net sudo bash basic-install.shThe installer asks for the interface (
eth0), upstream DNS servers and blocklist. Ubuntu's systemd-resolved holds port 53, so the installer turns off its stub listener. At the end it prints the web interface password; note it.Install WireGuard from Ubuntu's archive.
sudo apt-get install wireguard wireguard-toolsGenerate the server's keys in
/etc/wireguard.sudo -i cd /etc/wireguard umask 077 wg genkey | tee server.key | wg pubkey > server.pubStill as root, create
/etc/wireguard/wg0.confwith an editor such asnanoand put this in it:[Interface] Address = 10.100.0.1/24, fd08:4711::1/64 ListenPort = 47111Then add the private key and leave the root shell.
echo "PrivateKey = $(cat server.key)" >> /etc/wireguard/wg0.conf exitThe
fd08:4711::addresses exist only inside the tunnel. They work although the server has no public IPv6, which is not available in US East yet.Start WireGuard and check it.
sudo systemctl enable wg-quick@wg0.service sudo systemctl daemon-reload sudo systemctl start wg-quick@wg0 sudo wgIn the console, on the server's page under How to connect, forward a port of your block to port 47111 with protocol UDP. This guide uses 20001 as the public port.
Add a client, here called
phone. Generate its keys and a pre-shared key, add it to the server and reload without dropping other peers:sudo -i cd /etc/wireguard umask 077 name="phone" wg genkey | tee "${name}.key" | wg pubkey > "${name}.pub" wg genpsk > "${name}.psk" echo "[Peer]" >> /etc/wireguard/wg0.conf echo "PublicKey = $(cat "${name}.pub")" >> /etc/wireguard/wg0.conf echo "PresharedKey = $(cat "${name}.psk")" >> /etc/wireguard/wg0.conf echo "AllowedIPs = 10.100.0.2/32, fd08:4711::2/128" >> /etc/wireguard/wg0.conf wg syncconf wg0 <(wg-quick strip wg0)Then write the client's config, with Pi-hole as its DNS server:
echo "[Interface]" > "${name}.conf" echo "Address = 10.100.0.2/32, fd08:4711::2/128" >> "${name}.conf" echo "DNS = 10.100.0.1" >> "${name}.conf" echo "PrivateKey = $(cat "${name}.key")" >> "${name}.conf"Add the server as its peer with an editor. The endpoint is your shared IPv4 and the public UDP port from step 6, not 47111.
[Peer] AllowedIPs = 10.100.0.1/32, fd08:4711::1/128 Endpoint = 203.0.113.10:20001 PersistentKeepalive = 25Finish with the server's public key and the pre-shared key:
echo "PublicKey = $(cat server.pub)" >> "${name}.conf" echo "PresharedKey = $(cat "${name}.psk")" >> "${name}.conf" exitGive the next client
10.100.0.3, and so on. For a phone, Pi-hole's client script shows the file as a QR code withqrencode -t ansiutf8 < "${name}.conf"; install it first withapt install qrencode, a step that is ours.Make sure the listening mode is the safe default.
sudo pihole-FTL --config dns.listeningMode "LOCAL"
First login
Import the client config into the WireGuard app and connect. Then open http://10.100.0.1/admin, which travels through the tunnel, and sign in with the installer's password. Change it any time with sudo pihole setpassword.
In Query Log, queries from 10.100.0.2 show the phone uses Pi-hole. Add blocklists under Lists, then rebuild the blocklist database with pihole -g.
To reach the web interface without the tunnel, use SSH: ssh -p 20000 -L 8080:127.0.0.1:80 root@203.0.113.10, then http://localhost:8080/admin. That command is ours.
Secure it
In the console, go to Firewalls, New Firewall, Add Rule. Allow UDP 47111 from 0.0.0.0/0 for WireGuard and TCP 22 only from YOUR.IP/32, then attach the firewall on the server's page. Until one is attached, all traffic is allowed; once one is, anything you did not allow is dropped.
- Do not forward port 53 or the web interface's ports 80 and 443 from your block. DNS and the admin pages are for tunnel clients only.
- Keep the listening mode on
LOCAL. Pi-hole's docs call the other modes potentially dangerous on a public server. - Each client config holds a private key. Move it to the device securely, then delete the copy on the server.
Back it up
Pi-hole keeps everything in /etc/pihole: pihole.toml holds the settings, gravity.db the lists and your allow and deny entries, and pihole-FTL.db the long-term query history. The tunnel's keys are in /etc/wireguard. This archive command is ours:
sudo tar czf /root/pihole-wg-$(date +%F).tar.gz /etc/pihole /etc/wireguard
The archive contains private keys, so store it encrypted. The web interface also exports settings and lists as one file under Settings, Teleporter.
On VeloxaHost, snapshots are instant and free (5 on Starter, 30 on Pay as you go): server page, Snapshots, name, Create. Restoring overwrites the current state. Automatic snapshots run every hour, 6 hours, 12 hours, daily or weekly, kept for 1, 3, 7, 14 or 30 days. The Backups page creates, downloads and restores server backups (as a new server), on a schedule of every 6 hours, 12 hours, daily or weekly, keeping 1 to 10.
Update it
Take a snapshot, read the release notes for Pi-hole's Core, FTL and Web components, then run:
pihole -up
Pi-hole refreshes its blocklists every week on its own; pihole -g does it now. WireGuard comes from Ubuntu's archive and updates with the system's regular apt upgrades.
Troubleshooting
The app says connected, but nothing loads. Run sudo wg. Without a recent handshake for the peer, check that the forward is UDP, the firewall allows UDP 47111 and the client's endpoint uses the block port, such as 20001.
A handshake, but names do not resolve. Check DNS = 10.100.0.1 in the client config and that the listening mode is LOCAL, then watch Query Log.
The server lost DNS after you pointed it at Pi-hole. Pi-hole's post-install page warns about this: if Pi-hole fails, the host cannot resolve names, and repairs such as pihole -r need a working connection. Keep the server on its original resolver.
FAQ
Can I point my home router at Pi-hole on a VeloxaHost server?
Not sensibly. On the shared IPv4 address, DNS can only sit on a high port of your block, and routers ask for an address without a port. On a dedicated IPv4, Pi-hole would have to answer queries from the whole internet, or rely on a firewall rule for a home address that usually changes. Use a router with a WireGuard client instead.
Will my Pi-hole become an open resolver?
Not with this setup. The listening mode "Allow only local requests" answers only hosts on the server's own subnets, which here means tunnel clients. Port 53 is never forwarded from the shared address, so nobody else can query it.
Does all my traffic go through the server?
No. The client's AllowedIPs covers only 10.100.0.1, so only DNS queries and the admin pages use the tunnel. Pi-hole's WireGuard guide has a separate page for routing all traffic through the server.
What license is Pi-hole under?
Pi-hole is licensed under the European Union Public Licence (EUPL). It is free to use, and you can modify and redistribute it under the same licence.
Which VeloxaHost size fits Pi-hole?
A Veloxa Nano (1 vCPU, 1 GB RAM, 25 GB disk) at $4 a month, billed at $0.01 an hour and capped at the monthly price. Pi-hole needs 512 MB of RAM and a few gigabytes of disk, so the rest is room for large blocklists and a long query history.
Commands and settings checked on 2026-10-19 against the official documentation: docs.pi-hole.net, github.com. Software changes; if a step no longer matches, the vendor's docs win.
Ready to deploy?
Start a free trial, or compare plans to match your team's scale.