Installing Pi-Hole
Want to block ads and trackers across your entire network? In this post, I’ll show you how to install Pi-hole, the ultimate network-wide ad blocker, in just a few easy steps!

What in the World is a Pi-Hole?
At its core, Pi-Hole is a DNS sinkhole. Imagine a black hole for internet advertisements; that’s essentially what Pi-Hole creates on your network. It acts as a filter, catching and blocking ad-serving domains before they even have a chance to load on your devices. This means no more intrusive banners, no more pre-roll video ads, and a significant reduction in online tracking.
Originally designed to run on the humble Raspberry Pi (hence the name), Pi-Hole is a versatile piece of software that can be installed on any Linux machine. And thanks to the power of Docker, setting it up has never been easier.
But to truly appreciate how Pi-Hole works its magic, we first need to understand the role of a DNS server.
A Quick Detour: What’s a DNS Server?
Think of the internet as a gigantic city and every website or online service as a specific building. To get to any of these buildings, you need their address. In the digital world, this address is a numerical IP address (e.g., 172.217.16.142
).
Now, imagine having to remember the IP address for every website you visit. It would be an impossible task. That’s where the Domain Name System (DNS) comes in. DNS is the internet’s phonebook; it translates human-readable domain names (like google.com
) into computer-friendly IP addresses. Because remember: a computer can only communicate through IP addresses!
When you type a website address into your browser, your device sends a request to a DNS server. The DNS server looks up the corresponding IP address and directs your browser to the correct location. This all happens in the background in a matter of milliseconds.
Why Should You Bother with Pi-Hole?
So, why go through the trouble of setting up your own DNS server with Pi-Hole? The benefits are numerous and can significantly enhance your online life:
Network-Wide Ad-Blocking: Unlike browser extensions that only work on a single device, Pi-Hole protects every device connected to your network. This includes your smartphones, smart TVs, gaming consoles, and even your IoT gadgets.
Enhanced Privacy: Many ads and online trackers collect your data without your consent. By blocking these domains, Pi-Hole helps to safeguard your privacy and reduces your digital footprint.
Improved Performance: With fewer ads and trackers to load, web pages often load faster, leading to a snappier and more enjoyable Browse experience.
Deeper Network Insights: The Pi-Hole dashboard provides a wealth of information about your network’s activity. You can see which devices are making the most requests, which domains are being blocked, and get a better understanding of what’s happening under the hood.
Customizable Control: You are in complete control of your blocklists. You can add your own custom domains to block or whitelist sites that you want to support.
Installing Pi-Hole with Docker
Now for the fun part! We’re going to use Docker to get Pi-Hole up and running in just a few simple steps. Docker is a platform that allows you to run applications in isolated environments called containers, making the installation process clean and straightforward.
Prerequisites
A machine with Docker and Docker Compose installed. This can be a Raspberry Pi, a home server, or even your desktop computer running Linux. To install Docker, follow this guide.
Steps
Create a Directory and a Docker Compose File
cd # <- Goes to the home directory of your user
mkdir pihole
cd pihole
Create your docker-compose.yml
file
nano docker-compose.yml
Write your docker-compose.yml
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp" # DNS
- "53:53/udp" # DNS
- "8080:80/tcp" # HTTP
environment:
TZ: 'Europe/Rome'
WEBPASSWORD: 'your_super_secret_password'
volumes:
- './etc-pihole:/etc/pihole'
restart: unless-stopped
A Quick Breakdown of the docker-compose.yml
file:
services:
: Defines the different application services we want to run.pihole:
: The name of our service.container_name: pihole
: Gives our container a memorable name.image: pihole/pihole:latest
: Tells Docker to pull the latest official Pi-Hole image.ports:
: This is a crucial section. It maps the ports from the container to our host machine."53:53/tcp"
and"53:53/udp"
are for the DNS service."8080:80/tcp"
maps the container’s web server (port 80) to port 8080 on our host. We use 8080 to avoid potential conflicts with other services that might be running on port 80. (you can also use other ports than 8080, but don’t make sure to not use already-in-use ports!)
environment:
: Here, we set environment variables for the container.TZ
: Sets the timezone. You should change'Europe/Rome'
to your own timezone.WEBPASSWORD
: Sets the password for the Pi-Hole web interface. Remember to change'your_super_secret_password'
to something strong and memorable!
volumes:
: This tells Docker to store the Pi-Hole configuration files on our host machine. This is important so that our settings persist even if we update or recreate the container.restart: unless-stopped
: Ensures that the Pi-Hole container automatically restarts if it ever crashes, unless we manually stop it.
Start your Pi-Hole container
Save the docker-compose.yml
file (in nano
, press Ctrl+X
, then Y
, then Enter
). Now, from the same pihole
directory, run the following command to start your Pi-Hole container
docker compose up -d
Docker will now download the Pi-Hole image and start the container in the background. When done, you can check the status of your container by running the command
docker ps
You should see your pihole
container listed as “Up”.
Set up your router
We're almost there! Don't worry!
Now that Pi-Hole is running, the final step is to configure your router to use it as your DNS server. This will ensure that all the devices on your network are protected.
The exact steps will vary depending on your router’s make and model, but the general process is as follows:
Log in to your router’s web interface. You can usually do this by typing your router’s IP address (often
192.168.1.1
,192.168.0.1
or192.168.1.254
) into your web browser.Find the DNS server settings. This is often located in the “LAN” or “DHCP” settings section.
Enter the IP address of your Pi-Hole machine as the primary DNS server. To find the IP address of the machine running Docker, you can use the
ip a
orifconfig
command in the terminal.Save your changes and restart your router.
If you don’t find this setting in your router, then, you should manually change the DNS server on each device. It can be easily done for a phone or a computer, by going to Network Settings of the device. You can look up for the specific guide on how to do that for each device on Internet.
Once your router has restarted, your devices will start using Pi-Hole for DNS resolution, and you’ll be on your way to a cleaner, ad-free internet experience!
Access the Pi-Hole Web Interface
We've finally done it! To access the Pi-Hole dashboard, open your web browser and navigate to:
http://<your-pihole-ip-address>:8080/admin
Replace <your-pihole-ip-address>
with the IP address of the machine running Docker. You’ll be greeted with a login screen. Use the password you set in the docker-compose.yml
file to log in.
From the dashboard, you can monitor your network’s activity, manage your blocklists, and customize your Pi-Hole settings.
Conclusion
Setting up Pi-Hole is more than just about blocking ads; it’s about taking back control of your online experience. In a world where our data is constantly being collected and our attention is perpetually being vied for, Pi-Hole offers a powerful and accessible way to create a more private and peaceful digital environment.
With the help of Docker, the installation process is simpler than ever before. So why not give it a try? Your faster, cleaner, and more private internet awaits.
Last updated