Today, we’ll see how to install an ad blocker for your entire network in 15 minutes.
We’ll use Pi-Hole, which is a famous ad-blocker for Raspberry Pi.
Pi-Hole is a free and open-source ad-blocker. The source code is available on GitHub, and can be installed on Raspberry Pi OS with one command line:
curl -sSL https://install.pi-hole.net | sudo bash
In this post, I’ll start by introducing Pi-Hole, then show you how to install it and configure it on your network.
By the way, Pi-Hole is one of the many projects I introduce in my book “Master your Raspberry Pi in 30 days“. So, if you are really interested in improving your skills on Raspberry Pi, I highly recommend it. It’s a 30-days challenge from beginner to master, with step-by-step tutorials and many projects to practice along the way.
What is Pi-Hole?
As I said in the introduction, Pi-Hole is a free and open-source ad-blocker.
It’s different from AdBlock or other browser extensions because it’s directly on the network, it’s a DNS ad-blocker.
Pi-Hole has existed since 2014, and it works on most Linux distributions.
It’s available for Debian-like distributions (Debian, Raspberry Pi OS, Ubuntu) and also Fedora/CentOS.
What is a DNS Ad-Blocker?
You probably know or use AdBlock to get the same results.
But AdBlock depends on your browser.
If you have AdBlock on Google Chrome and switch to Firefox, ads are back.
Also, it’s not possible to use it on mobile (or at least with any system/browser).
A DNS ad-blocker is easier to manage because once you install Pi-Hole, you can use it directly with any device on the same network.
Just set your DNS server with the Raspberry Pi IP, and that’s it, you don’t have ads anymore.
Let’s move now to the installation process, it’s straightforward.
Pi-Hole is a lightweight software, and it’s designed especially for Raspberry Pi.
So, you can use it with any Raspberry Pi model.
In my case, I’m using my Raspberry Pi Zero for this (I have this kit), it’s working very well.
If you don’t have a Raspberry Pi yet, you can follow the same procedure with a Linux computer, or even a virtual machine running on Linux.
Pi-Hole is working on Raspberry Pi OS, so there is no need to take a specific SD card or buy a Raspberry Pi just for this.
You can use any Raspberry Pi you have.
If you already have one running all day, you can use that one.
If you need to install Raspberry Pi OS, check my guide here on how to install it on Raspberry Pi.
Raspberry Pi OS Lite is fine if you don’t need the graphical interface for something else.
Before continuing, make sure you have:
- Raspberry Pi OS installed
- Network working
Wired or wireless is ok on a small network, it’s just for DNS requests
- An up-to-date system with the latest packages
sudo apt update && sudo apt upgrade -y
- SSH access enabled
sudo service ssh start
And that’s it, you’re ready to go!
Download and Install
Pi-Hole is available on this GitHub repository, and they have a one-line command to install it easily.
- Connect to your Raspberry Pi with SSH.
If you don’t know the IP address, follow this tutorial on how to find the Raspberry Pi IP address.
Login with pi and your password (raspberry by default).
- Copy and paste this command:
curl -sSL https://install.pi-hole.net | sudo bash
The installation starts with an ASCII art 🙂
- Then a standard Debian wizard will start
- Answer Ok to the three firsts questions, no other choices anyway 🙂
- Then the following message tells you that you need a static IP.
It’s not mandatory, but if the IP changes, you’ll lose Internet, so I recommend doing this.
You can also fix the IP address in your DHCP server.
- Choose the Interface to use
eth0 for a wired connection, wlan0 in WiFi.
- Then you have to choose a DNS provider.
Pi-Hole will forward all requests to DNS servers after filtering them
You can take the default one (Google) and change it later if needed
- The wizard now asks you to select third-party lists to use for blocking ads:
I think you can keep them all, and change/add some later.
- The next question is about IPv4/IPv6 protocols.
Make your choice, or keep default values if you don’t know.
- Then it asks you about the static IP settings:
I recommend clicking on Yes to fix your IP address.
- The next screen is a warning message about using DHCP and static IP on the same network range:
But most of the time the router will detect your Raspberry Pi and not assign this IP to another one.
- Then it gives you the IPv6 address if you chose to keep it enabled.
- Then the wizard asks you to enable the web admin interface:
I highly recommend doing this, it’s a major feature in Pi-Hole and you’ll love it.
- In the next step, you need to confirm the Lighttpd installation
It’s mandatory to get the interface working, so choose “On.”
- Now, you need to choose if you want to enable queries log.
The software will store any DNS request you make and display stats about them.
I recommend enabling it for the moment, you can disable it later on the interface.
- Finally, there is a privacy mode to select between five levels.
Same thing, you can change it later:
If you are installing it for a company, make sure you have permission to enable queries log and display every request details, it’s probably something to consult your legal department about.
Ok, it was a long wizard, but basically, you can just keep the default value for each screen 🙂
You can change everything later with the web interface.
After this, the installation process continues by downloading and installing new packages based on your choices.
Don’t miss the last screen as it will give you the web interface address and the login password:
I’ll explain the web interface in the next section.
But before that, we need to tell the clients to use the new DNS server.
The easiest way to configure all devices at once is to change your DHCP server configuration.
At home, it’s probably your Internet router that takes this role.
I’ll not explain this in detail, as it’s different on each router.
It can be in the DHCP settings or in the DNS settings.
For me, it’s in the DNS settings.
The only thing to do is to remove all values and set the primary DNS server as 192.168.1.17.
That’s my Raspberry Pi IP address, set it with your own.
Don’t set a secondary IPv4 DNS server, except if you have two Raspberry Pi with Pi-Hole on your network.
This way, any device using DHCP will now use the Pi-Hole ad-blocker from your network as a DNS server.
It can take a few hours to update the device settings on all devices, be patient or disconnect/reconnect them manually.
If you don’t have access to these settings or want to make a try first, you can edit only your computer settings:
On Windows 10:
- Right-click on the “Start Menu” and choose “Network Connections”
- Then click on “Change adapter settings”
- Right-click on your current connection and choose “Properties”
- Double-click on “Internet Protocol Version 4 (TCP/IPv4)”
- Set the DNS server to static and enter your Raspberry Pi IP Address
Keep the secondary DNS server empty
On Linux and Mac OS:
- If you have a graphical interface, you’ll find the network settings in the System Preferences
- If not, you can edit the /etc/resolv.conf file and replace the current DNS server with the Raspberry Pi IP address
On mobile, it’s in your WiFi settings.
Click details or edit network on a network to see the DNS configuration.
Pi-Hole Web Interface
Pi-Hole comes with a great web interface, let’s check this now.
To access the web interface, open your browser and go to http://<RASPBERRYPI_IP>/admin
In my case, it’s http://192.168.1.17/admin
If you didn’t note the IP address during the installation wizard, you can find it with “ifconfig.”
Once on the web page, click Login and enter the password you got previously.
If everything is correct, you’ll get something like this:
On this page, you can see all the statistics about your Internet usage:
- Total queries: how many requests you made
- Queries blocked: how many requests it blocked
- Percent Blocked = queries blocked / total queries
- Domains on Blacklist: how many domain names you have on the blacklists
There are also graphs about queries and clients’ evolution in recent hours.
Two pie charts show data about query types.
And below (we don’t see it in the picture), it lists top domains and top blocked domains, and the same thing for clients.
That’s pretty cool, and it’s only the first page 🙂
In the main menu you’ll find links to the other pages and sections:
- Dashboard: the page we just saw
- Query Log: if enabled, all the queries you made and if Pi-Hole blocked them or not
- Long-term data: the dashboard is showing data about the last 24 hours, in this section, you can specify the date range
- Whitelist: here you can add domains to the whitelist (if they are on a blacklist and you don’t want to block them). For example, I’m using Google Analytics for this website, and it’s on the blacklist, so I added the URL here
- Disable: Sometimes you may need to disable Pi-Hole for a few minutes or permanently to do something specific on your computer. This is where you can do it
- Tools: a bunch of tools to debug Pi-Hole, I will let you discover this part
- Settings: all the configuration menus, we’ll come to this in the next paragraph
- Log out / Donate / Help: these should be clear 🙂
If you have any questions about one menu item, leave a comment below and I’ll try to help you
Let’s look especially at the settings part now.
When you click on the “Settings” menu item, you’ll get 7 tabs with settings forms:
Basically, you can edit here all the things you previously chose in the installation wizard.
- System: In this first tab, you can check information about the network and the Pi-Hole version and usage. You have also a “Danger Zone” to restart services, reboot Raspberry Pi, or clear logs
- Adlists: In this tab, you can manage blacklisted domains. You can disable or delete default blacklists, or add a new one
- DNS: DNS tab is where you can change your DNS providers and configure more advanced DNS settings
- DHCP: This tab allows you to enable a DHCP server on Pi-Hole. That’s another way to configure clients if your current router doesn’t do this. Don’t forget to disable the old DNS server if you want to try this
- API / Web interface: The next tab is for various settings about the interface. You can mask domains for the dashboard and customize the interface display
- Privacy: In this tab, you can change the privacy level we saw in the installation wizard to increase or decrease the privacy level on the interface
- Teleporter: Finally, what they call “Teleporter” is just an Import/Export tool, to move the configuration from a Raspberry Pi to another
Before ending this tutorial, there are a few other things you need to know about Pi-Hole.
Update the Blacklist
As you can guess, domain blacklists are changing every day.
Like antivirus software, you need to update them regularly to maintain good protection.
To do this, go to Tools > Update Gravity and click on Update.
Pi-Hole will download each blacklist file from the specified sources and reload the configuration.
The other thing you need to update is the software.
Pi-Hole is releasing updates and fixes regularly, so you need to update it.
To do this, the procedure is simple:
- Connect to your Raspberry Pi via SSH
- Type this command:
sudo pihole -up
- You’ll get something like this:
- In my case, I’m already up to date, but if there is an update, you’ll see it here.
Is there a way to use Pi-Hole to block more than ads domains? Yes, you can add your custom domain names and list. So, you can use it to block any domains: not safe for kids, specific domains, or websites known to install malware.
What can I do if it blocks a useful website? If you have websites that you often use not working after the Pi-Hole configuration, you can add the domain name in the whitelist menu to unblock it.
That’s it, you know everything you need about how to install Pi-Hole on Raspberry Pi.
I hope this will help you to remove ads and block undesired domains.
If you have any other questions, leave a comment, and I’ll try to answer you.
Thanks to share this post by using the buttons below!