Skip to content

How to Set Up Pi-hole on a Linux Server – Filter Ads and Trackers with DNS

Pi-hole on a Linux server: as a One-Click App with DNS only for your IP, or with Docker Compose and WireGuard Easy, without an open resolver.

1 December 202613 min read1 Views0 helpful

Introduction

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.

When Pi-hole on a VPS makes sense

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.

Network firewall or VPN?

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 IPVPN with WireGuard Easy
Suitable forHome network or office with a static IP addressSmartphone, laptop on the go, dynamic IP addresses
SetupRules in the ZapX dashboardWireGuard app on each device
Port 53 on the internetOpen only to your IP addressesNot open at all
Works withOne-Click App with PIHOLE_DNS_BIND_ADDRESSManual 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.

The easy way: Pi-hole as a One-Click App

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.

Requirements

  • 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.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.

  2. Search the app catalog for Pi-hole and click Install app.

  3. 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.

  4. Under App configuration, there are three optional fields:

    • PIHOLE_DNS_BIND_ADDRESS (default 127.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, default Europe/London): for Germany, use Europe/Berlin.
    • FTLCONF_dns_listeningMode (default all): leave this set to all; 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.

  5. 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.

First login

  1. Open the Access link on the app card and add /admin to the address, for example, https://pihole.example.com/admin. Without /admin, the address only displays an error page.
  2. 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.

Allow DNS for your IP address

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.

  1. Click Add rule. Set Direction to IN, Action to ACCEPT, and Service template to DNS. Enter your public IP address under Source, add a Comment such as “Pi-hole: my IP”, and click Create.
  2. Add a second rule with IN, DROP, and the Service template set to DNS, 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:

  1. Click the gear on the app card and go to App environment.
  2. For PIHOLE_DNS_BIND_ADDRESS, enter the public IPv4 address of your VPS. You can find it in your VPS overview in the dashboard.
  3. Click Save. The app will restart with the new address.
Warning: Don’t enter 0.0.0.0

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:

Code
dig @SERVER_IP example.com

You’ll get a response from your allowed IP address. Requests from any other address will time out.

Info: Dynamic IP address at home

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 and backups

  • 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-data volume. 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.
Info: Older installations: DNS only responds locally after an update

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.

Manual installation

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.

Requirements

  • 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.com for the Pi-hole web interface and vpn.example.com for WireGuard Easy.

Pi-hole itself uses very few resources. The figures below come from the official documentation and apply to Pi-hole alone:

MinimumRecommended
CPU1 core1 core
Memory512 MB1 GB
Free disk space2 GB4 GB

Prepare the firewall

Only SSH, HTTP, and HTTPS for the reverse proxy, as well as the WireGuard port, need to be accessible from the internet:

Code
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.

Install with Docker Compose

Create a directory and create the docker-compose.yml file inside it:

Code
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:

Code
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 all INIT_... values, this is only used on the very first startup.
  • ipv4_address: Both containers get a fixed address on the shared wg network. This ensures that clients’ DNS settings always point to Pi-hole.
  • No port 53 under ports: Pi-hole is only reachable on the wg network, 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 to ALL allows Pi-hole to respond to them. This is safe here because the port isn’t published.
  • 127.0.0.1:8080:80 and 127.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:

Code
docker compose up -d
Warning: Never publish port 53 on all addresses

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.

First visit

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:

Code
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.

Access over HTTPS through a reverse proxy

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:

Code
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;.

Back up your data

All Pi-hole data is stored in /opt/pihole-vpn/etc-pihole. To back it up, briefly stop the containers and archive the directories:

Code
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.

Update Pi-hole

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:

Code
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.

Connect devices and manage lists

Connect devices through the VPN

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.

Connect devices directly with a static IP

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.

Lists and query log

  • 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.

Limitations

  • 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.

Conclusion

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.

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the quickest option: Pi-hole runs with an HTTPS web interface after a few clicks, and you can install updates in the ZapX dashboard under App update. By default, DNS only responds on the server itself. To use it on your home network, allow port 53 for your IP address in the network firewall and enter your server’s IP address in PIHOLE_DNS_BIND_ADDRESS. If you don’t have a static IP or want to use Pi-hole on the go, the manual installation with Docker Compose and WireGuard Easy is a better fit: port 53 isn’t reachable from the internet at all.
A DNS server that responds to everyone is an open resolver. Attackers can send it requests with a forged sender address and use its larger responses to flood other servers with traffic (DNS amplification). Your server then becomes a tool for the attack. Only allow port 53 for your own IP addresses, or use Pi-hole through a VPN.
The One-Click App generates the password during installation. Find it by clicking the gear on the app card and going to App environment > Automatically generated values, where it appears as SERVICE_PASSWORD_PIHOLE. There’s no username. For a manual installation, use the value of FTLCONF_webserver_api_password in your Compose file. Access the web interface by adding /admin to your address.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.