Pi-Hole installation guide on Raspberry Pi

How to install Pi-Hole on Raspberry Pi? (Free ad blocker in 15min)

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

How to install Pi-Hole on Raspberry Pi?
Pi-Hole is a free and open source ad-blocker you can use on Raspberry Pi
You can install it on Raspbian, so there is no need to dedicate a Raspberry Pi for this
Download the source code from GitHub and follow the procedure below

In this post, I’ll start by introducing Pi-Hole, then show you how to install it and configure it on your network

Pi-Hole presentation

pihole logo

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 exists since 2014 and it works on most of Linux distributions
It’s available for Debian-like distributions (Debian, Raspbian, 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, as you install Pi-Hole once, and 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

Pi-Hole installation

Let’s move now to the installation process, it’s straightforward

Hardware

Pi-Hole is a lightweight software, and it’s designed specially 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, 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

Operating system

Pi-Hole is working on Raspbian, 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 Raspbian, check my guide here on how to install Raspbian on Raspberry Pi
Raspbian Lite is fine if you don’t need the graphical interface for something else

Before continuing, make sure you have:

  • Raspbian 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
  • Enabled SSH access
    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 🙂

    ascii pi hole

  • 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 this 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 lighthttpd 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 in a company, make sure you have permission to enable queries log and display every request details, it’s probably something to see with your legal department

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

Client configuration

DHCP configuration

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 details 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
It’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 DNS server
It can take a few hours to update the devices settings on all devices, be patient or disconnect/reconnect them manually

Static configuration

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:

  • Do a right click on the “Start Menu” and choose “Network Connections”
  • Then click on “Change adapter settings”
  • Do a 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 by 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

First login

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:

pihole web interface

The Pi-Hole web interface

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 in the blacklists

Then you have graphs about queries and clients evolution in the last hours
Then two pie charts about queries types
And below (we don’t see it on the picture), you have top domains and top blocked domains, and the same thing for clients

That’s pretty cool, and it’s only the first page 🙂

Menu sections

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: 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 whitelist (if they are in a blacklist and you don’t want to block them). For example, I’m using Google Analytics for this website, and it’s in 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 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

Settings

Let’s look specially to the settings part now
When you click on the “Settings” menu item, you’ll get 7 tabs with settings forms
pihole settings tabs

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
  • Blocklists: In the blocklists, 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

Pi-Hole tips

Before ending this tutorial, there are a few other things you need to know about Pi-Hole

Update the blacklist

As you can guess, domains blacklists are changing everyday
Like an antivirus software, you need to update them regularly to keep a 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

Update software

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 Raspbian via SSH
  • Type this command:
    sudo pihole -up
  • You’ll get something like this:
    pi-hole update
  • In my case I’m already up to date, but if there is an update, you’ll see it here

Related Questions

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 to 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

Conclusion

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!

 

Leave a Comment