Deploying Pi-hole on Linux for Network-Wide Privacy
A practical guide to blocking trackers and ads across your network using Pi-hole on Linux without any cloud storage service.

Get Rid of Network Ads & Trackers Using Pi-hole on Linux
After this tutorial you will learn :
how to block ads and trackers on your network
How to setup and configure pi hole on linux
How to install Pi-Hole :
When an user enters domain which contains ads , Pi-hole returns an empty response. As a result, devices on the local network do not load trackers or telemetry scripts. This system works without installing any client software installations. Follow these steps given below :
Step 1: Assign a Static IP Address
A DNS server must keep a static address. If the host address changes, connected clients lose network resolution.
Check your current interface name and IP address:
ip -br addr show
Open the network configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
Set a static IP values for your interface:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.10/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 9.9.9.9]
Apply and save the network configuration:
sudo netplan apply
Step 2: Install Docker and Docker Compose
Containerized deployment keeps the host clean. It also allows quick backup and rollbacks.
Update required repositories:
sudo apt update && sudo apt upgrade -y
Install Docker and the Compose plugin:
sudo apt install -y docker.io docker-compose-v2
Add the user to the Docker :
sudo usermod -aG docker $USER
Enable and Run the Docker daemon:
sudo systemctl enable --now docker
Step 3: Fix Port 53 Conflicts
On Ubuntu or Debian systems, systemd-resolved frequently binds to port 53. Disable this listener before starting Pi-hole.
Check if port 53 is already in use:
sudo ss -tulpn | grep :53
If systemd-resolved holds port 53, edit its configuration file:
sudo nano /etc/systemd/resolved.conf
Set the DNS stub listener to disabled:
[Resolve]
DNS=1.1.1.1
DNSStubListener=no
Create a symlink for the system resolver file:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
Restart the resolver service:
sudo systemctl restart systemd-resolved
Step 4: Configure the Docker Compose Service
Create an application directory for Pi-hole files:
mkdir -p ~/pihole && cd ~/pihole
Create a docker-compose.yml file:
nano docker-compose.yml
Add the service configuration below:
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "80:80/tcp"
environment:
TZ: 'UTC'
WEBPASSWORD: 'SetAStrongPasswordHere'
FTLCONF_LOCAL_IPV4: '192.168.1.10'
volumes:
- './etc-pihole:/etc/pihole'
- './etc-dnsmasq.d:/etc/dnsmasq.d'
restart: unless-stopped
CAUTION: Do not use weak passwords in the WEBPASSWORD environment variable. Anyone on your local subnet can access the administrative dashboard if the password is weak.
Start the container in detached mode:
docker compose up -d
Step 5: Verify Container Operation
Check container status:
docker compose ps
Test DNS resolution locally through the container:
dig @127.0.0.1 doubleclick.net
The output must show 0.0.0.0 as the answer IP address:
;; ANSWER SECTION:
doubleclick.net. 2 IN A 0.0.0.0
Now test an allowed domain:
dig @127.0.0.1 paragraph.xyz
The output will return the real public IP address.
Step 6: Route Network Traffic Through Pi-hole
You have two options to route client traffic to Pi-hole:
Router-Level DNS (Recommended): Log in to your home router. Change the primary DNS server address in DHCP settings to
192.168.1.10. All connected clients will automatically query Pi-hole.Device-Level DNS: On a single laptop or mobile device, open network adapter settings. Replace automatic DNS with
192.168.1.10.
Step 7: Add Privacy Blocklists
Open your web browser and navigate to the web dashboard:
http://192.168.1.10/admin
Log in with the password you defined in docker-compose.yml.
Navigate to Adlists in the left menu. Add trusted open-source blocklists such as Firebog curated lists:
https://v.firebog.net/hosts/AdguardDNS.txthttps://v.firebog.net/hosts/Easyprivacy.txt
Update the internal gravity database to pull the new domains:
docker exec -it pihole pihole -g
Maintenance and Updates
Keep your Pi-hole container updated to get upstream security patches:
cd ~/pihole
docker compose pull
docker compose up -d
You now have a private DNS sinkhole running on Linux. It prevents unwanted data collection across all devices on your local network.
Join the discussion
Have a thought or a correction? Send it over — your message opens in your email app.