Pi-hole is a DNS server with built-in ad and tracking filters. Devices that use Pi-hole as their DNS server no longer receive addresses for known ad, tracking, and malware domains. This lets you filter ads for all your devices at once without installing an ad blocker on each device. In a web interface, you can see which domains were requested and blocked, and manage blocklists and allowlists.
There’s one thing to keep in mind when running Pi-hole on a VPS: your server is directly connected to the internet. A DNS server that responds to everyone is an open resolver and can be abused in attacks. That’s why this guide covers not only the installation, but also how to make port 53 accessible only to you. We’ll show you two ways: the simple option using the One-Click App, where DNS responds only on the server itself by default and you can explicitly allow your IP address, and the manual installation with Docker Compose, where Pi-hole is accessible only through your own VPN with WireGuard Easy.
Pi-hole on a VPS is worthwhile if:
- You want to filter ads and trackers while you’re away from home: Connect to your server through a VPN, and your smartphone can use Pi-hole over mobile data or on other Wi-Fi networks.
- You don’t want to keep a device running at home, such as a Raspberry Pi, and your server is already running around the clock.
- You want your own DNS server with logging: You can see which devices request which domains, and block or allow individual domains.
- You want to provide the same lists at multiple locations, such as your home and a small office.
A VPS is less suitable if you want to use Pi-hole as a DHCP server for your home network or resolve devices on your home network by name. For that, Pi-hole needs to be on the same local network. If you have a dynamic IP address at home and don’t want to use a VPN, a device on your home network is also the simpler choice.
How you use Pi-hole depends on where you’re connecting from. Both options prevent your server from becoming an open resolver:
| Network firewall with your own IP | VPN with WireGuard Easy | |
|---|---|---|
| Suitable for | Home network or office with a static IP address | Smartphone, laptop on the go, dynamic IP addresses |
| Setup | Rules in the ZapX dashboard | WireGuard app on each device |
| Port 53 on the internet | Open only to your IP addresses | Not open at all |
| Works with | One-Click App with PIHOLE_DNS_BIND_ADDRESS | Manual installation in this guide |
A firewall on the server itself, such as ufw, isn’t sufficient for Pi-hole in Docker: Docker adds published ports outside of ufw, so port 53 would be reachable from the internet despite the rule. The Network firewall in the ZapX dashboard, on the other hand, filters traffic before it reaches your server and also applies to Docker.
Use your VPS’s One-Click Apps to install Pi-hole in just a few clicks. The web interface is accessible directly over HTTPS using a domain, and the app generates the password for you. By default, DNS only responds on the server itself (127.0.0.1). This means your server isn’t an open resolver immediately after installation. You can then explicitly allow port 53 for your devices at home.
- A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set up One-Click Apps for instructions.
- A static IP address at the location where you want to use Pi-hole. If you don’t have a static IP, use the VPN method in the manual installation section.
-
Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
-
Search the app catalog for Pi-hole and click Install app.
-
Use a custom subdomain or zap.cloud is already selected, with a randomly generated name. Leave the option enabled or enter your own name. You’ll use the domain to access the web interface over HTTPS.
-
Under App configuration, there are three optional fields:
PIHOLE_DNS_BIND_ADDRESS(default127.0.0.1): the address on which Pi-hole accepts DNS requests. Leave the default during installation; you’ll allow access in the next section.TZ(time zone, defaultEurope/London): for Germany, useEurope/Berlin.FTLCONF_dns_listeningMode(defaultall): leave this set toall; otherwise, Pi-hole won’t respond to requests coming from outside the container when running in Docker.
The app generates the web interface password (
SERVICE_PASSWORD_PIHOLE) automatically. -
Click Queue installation.
The app doesn’t publish DHCP (port 67) or NTP (port 123). You don’t need either on a VPS in a data center.
- Open the Access link on the app card and add
/adminto the address, for example,https://pihole.example.com/admin. Without/admin, the address only displays an error page. - Pi-hole only asks for a password; there is no username. Find the password by clicking the gear on the app card and going to App environment > Automatically generated values, where it appears as
SERVICE_PASSWORD_PIHOLE. Click the eye icon to show it, or the icon next to it to copy it.
The app sets the password and listening mode using environment variables. That’s why Pi-hole only displays these settings in the web interface; you can’t change them there.
For your devices at home to use Pi-hole, port 53 must be reachable from the internet, but only by you. First, create the rules in the Network firewall, then change the address in the app. This ensures port 53 is never open to everyone.
Create two rules in the Network firewall tab for your VPS. Rules are checked from top to bottom, and the first matching rule applies. So the rule allowing your IP address must be above the rule blocking everyone else.
- Click Add rule. Set Direction to
IN, Action toACCEPT, and Service template toDNS. Enter your public IP address under Source, add a Comment such as “Pi-hole: my IP”, and click Create. - Add a second rule with
IN,DROP, and the Service template set toDNS, this time without a Source. This blocks port 53 for everyone else.
Check the order in the list and move the allow rule to the top using the arrows if needed. To allow multiple addresses, such as your home and office, combine them in an IP set and enter +name under Source.
Then change the address in the app:
- Click the gear on the app card and go to App environment.
- For
PIHOLE_DNS_BIND_ADDRESS, enter the public IPv4 address of your VPS. You can find it in your VPS overview in the dashboard. - Click Save. The app will restart with the new address.
With 0.0.0.0, Pi-hole listens on all of the server’s addresses. On Ubuntu, the app won’t start because the systemd-resolved service occupies port 53 on the server itself. Using the public IPv4 address avoids this conflict. Without the rules in the Network firewall, your server would be an open resolver in either case: a firewall on the server itself, such as ufw, won’t help because Docker bypasses it.
Test whether the block rule works with dig or nslookup from a device outside your network, such as a smartphone on mobile data using a DNS app, or another server:
dig @SERVER_IP example.com
You’ll get a response from your allowed IP address. Requests from any other address will time out.
Most home internet connections are assigned a new IP address regularly. You’ll then need to update the allow rule each time, or your devices will stop receiving DNS responses. In this case, a VPN is the better option.
- Updates: Click the gear on the app card, go to App update, and click Check for updates. If a new version is available, install it by clicking Apply update. Pi-hole updates its blocklists automatically once a week.
- Backup: Settings, lists, and statistics are stored in the
pihole-datavolume. It’s included in your VPS Backups. You can also export the configuration in Pi-hole under “Settings” > “Teleporter” as a file that you can import into any other Pi-hole installation.
Earlier versions of the app responded to DNS requests on all of the server’s addresses. After an App update, they also use PIHOLE_DNS_BIND_ADDRESS: if no address is entered, Pi-hole only accepts DNS requests on the server itself. If you access Pi-hole from outside, set up the rules in the Network firewall and enter your VPS’s public IPv4 address as described above.
If you don’t use One-Click Apps, you can install Pi-hole with Docker Compose. We’ll pair Pi-hole with WireGuard Easy so port 53 isn’t reachable from the internet at all: your devices connect to the server through a VPN and use Pi-hole over the VPN. For an introduction to WireGuard Easy, see How to set up WireGuard Easy on a Linux server.
- A Linux VPS running Debian or Ubuntu with root access via SSH.
- Docker with Docker Compose. See How to set up Docker on a Linux server.
- A domain or subdomain with an A record pointing to your server, for example,
pihole.example.comfor the Pi-hole web interface andvpn.example.comfor WireGuard Easy.
Pi-hole itself uses very few resources. The figures below come from the official documentation and apply to Pi-hole alone:
| Minimum | Recommended | |
|---|---|---|
| CPU | 1 core | 1 core |
| Memory | 512 MB | 1 GB |
| Free disk space | 2 GB | 4 GB |
Only SSH, HTTP, and HTTPS for the reverse proxy, as well as the WireGuard port, need to be accessible from the internet:
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 51820/udp
ufw enable
Don’t open port 53. The Compose file below doesn’t publish it either, so Pi-hole is only reachable within the Docker network used by WireGuard Easy. For more information about ufw, see Firewall management on Linux.
Create a directory and create the docker-compose.yml file inside it:
sudo mkdir -p /opt/pihole-vpn
cd /opt/pihole-vpn
sudo nano docker-compose.yml
Add the following content. It follows the official WireGuard Easy Compose file (as in our WireGuard Easy guide) and the WireGuard Easy developers’ example for a DNS filter on the VPN:
volumes:
etc_wireguard:
services:
wg-easy:
image: ghcr.io/wg-easy/wg-easy:15
container_name: wg-easy
environment:
- INIT_ENABLED=true
- INIT_USERNAME=admin
- INIT_PASSWORD=WG_PASSWORD
- INIT_HOST=vpn.example.com
- INIT_PORT=51820
- INIT_DNS=10.42.42.53
networks:
wg:
ipv4_address: 10.42.42.42
ipv6_address: fdcc:ad94:bacf:61a3::2a
volumes:
- etc_wireguard:/etc/wireguard
- /lib/modules:/lib/modules:ro
ports:
- "51820:51820/udp"
- "127.0.0.1:51821:51821/tcp"
restart: unless-stopped
cap_add:
- NET_ADMIN
- SYS_MODULE
sysctls:
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.src_valid_mark=1
- net.ipv6.conf.all.disable_ipv6=0
- net.ipv6.conf.all.forwarding=1
- net.ipv6.conf.default.forwarding=1
pihole:
image: pihole/pihole:2026.11.0
container_name: pihole
environment:
TZ: 'Europe/Berlin'
FTLCONF_webserver_api_password: 'PIHOLE_PASSWORD'
FTLCONF_dns_listeningMode: 'ALL'
networks:
wg:
ipv4_address: 10.42.42.53
volumes:
- ./etc-pihole:/etc/pihole
ports:
- "127.0.0.1:8080:80/tcp"
restart: unless-stopped
networks:
wg:
driver: bridge
enable_ipv6: true
ipam:
driver: default
config:
- subnet: 10.42.42.0/24
- subnet: fdcc:ad94:bacf:61a3::/64
Replace WG_PASSWORD, PIHOLE_PASSWORD, and vpn.example.com with your own values. Choose long passwords without $ characters; otherwise, Docker Compose will read them as variables. Here are the most important lines:
INIT_DNS=10.42.42.53: On first startup, WireGuard Easy sets Pi-hole as the DNS server for all new clients. Like allINIT_...values, this is only used on the very first startup.ipv4_address: Both containers get a fixed address on the sharedwgnetwork. This ensures that clients’ DNS settings always point to Pi-hole.- No port 53 under
ports: Pi-hole is only reachable on thewgnetwork, meaning it’s available to your VPN clients but not from the internet. FTLCONF_dns_listeningMode: 'ALL': On the Docker network, requests come from a different network than Pi-hole’s own. Setting this toALLallows Pi-hole to respond to them. This is safe here because the port isn’t published.127.0.0.1:8080:80and127.0.0.1:51821:51821: The web interfaces are only reachable on the server itself. The reverse proxy handles access from the internet../etc-pihole: Pi-hole stores its settings, lists, and query log database here.
Start both containers:
docker compose up -d
Many guides for Pi-hole on a home network include the lines "53:53/tcp" and "53:53/udp". On a VPS, these make your server an open resolver, and Docker also bypasses ufw. If you do need port 53 accessible from the internet, restrict it to your IP addresses using the Network firewall, as described in the easy method.
Check whether Pi-hole is running with docker compose logs pihole. To take a first look at the web interface without a domain, open an SSH tunnel from your computer:
ssh -L 8080:127.0.0.1:8080 root@SERVER_IP
Then go to http://localhost:8080/admin in your browser and sign in with the password set in FTLCONF_webserver_api_password.
To access Pi-hole using your domain, set up nginx as a reverse proxy as described in How to set up a reverse proxy with nginx. A server block for Pi-hole looks like this:
server {
listen 80;
server_name pihole.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Then obtain the certificate with certbot --nginx -d pihole.example.com. See Create an SSL certificate. You can then access the web interface at https://pihole.example.com/admin. For WireGuard Easy, create a second block for vpn.example.com with proxy_pass http://127.0.0.1:51821;.
All Pi-hole data is stored in /opt/pihole-vpn/etc-pihole. To back it up, briefly stop the containers and archive the directories:
cd /opt/pihole-vpn
docker compose stop
tar czf pihole-backup-$(date +%F).tar.gz etc-pihole docker-compose.yml
docker compose start
WireGuard Easy data is stored in the Docker volume etc_wireguard. See the WireGuard Easy guide for instructions on backing it up. For Pi-hole alone, exporting through “Settings” > “Teleporter” is often sufficient.
Enter the new version in the Compose file. You can find the list in the docker-pi-hole releases. Then pull the image and restart the container as described in the official documentation:
cd /opt/pihole-vpn
docker compose pull
docker compose up -d
Your settings and lists will be preserved because they’re stored outside the container.
Create a client in WireGuard Easy for each device and connect it using a QR code or configuration file, as described in the WireGuard Easy guide. New clients automatically get Pi-hole as their DNS server. To change the DNS server for all clients later, go to “Admin Panel” > “Config” > “DNS”, then redistribute the configurations. You’ll find the same field in each individual client’s settings.
If a client routes only some of its traffic through the VPN (split tunneling), 10.42.42.0/24 must be listed under “Allowed IPs”; otherwise, it won’t be able to reach Pi-hole.
If you’re using the One-Click App with access allowed in the Network firewall and PIHOLE_DNS_BIND_ADDRESS set, enter your server’s IP address as the DNS server. The easiest way is to set it in your router, so all devices on your home network will use Pi-hole automatically. Don’t add a second, public DNS server alongside it, or devices may bypass the filter.
- Blocklists: Pi-hole comes with a default list. Add more under “Group Management” > “Lists”. Then load them immediately under “Tools” > “Update Gravity”; otherwise, they’ll be loaded during the next weekly update.
- Individual domains: Under “Group Management” > “Domains”, block or allow individual domains if a website or app doesn’t work because one of its domains is blocked.
- Query log: Under “Query Log”, you can see every request, along with the device and result. You can also allow a blocked domain with one click.
- Upstream DNS: Under “Settings” > “DNS”, choose which DNS servers Pi-hole forwards requests to when they aren’t blocked.
- No encrypted DNS: Pi-hole only responds to requests over standard DNS on port 53, not through DNS-over-HTTPS or DNS-over-TLS. You therefore can’t enter Pi-hole in Android’s “Private DNS” field. When using a VPN, the connection to the server is still encrypted.
- Not all ads can be filtered: A DNS filter can’t block ads served from the same domain as the content, such as on YouTube.
- No DHCP or device names: Pi-hole on a VPS isn’t on your home network. It can’t assign addresses there, and the log shows your devices by their public or VPN IP address instead of their names.
With Pi-hole on your VPS, you can filter ads and trackers for all your devices, at home and on the go. The quickest option is the One-Click App: by default, it only responds to DNS requests on the server itself. Add two rules to the network firewall and enter your server’s IP in PIHOLE_DNS_BIND_ADDRESS to allow access only from your own IP address. If you don’t have a static IP, pairing Pi-hole with WireGuard Easy is the secure option: port 53 stays closed, and your devices use Pi-hole through the VPN.
