# Setting up Pi-hole to Block Ads on Your Local Network

{% hint style="danger" %} <sub><mark style="color:red;">Disclaimer — Educational Use Only and Liability Limits<mark style="color:red;"></sub>

<sub><mark style="color:red;">The procedures and information described in this article are provided for<mark style="color:red;"></sub> <sub><mark style="color:red;"> </sub><sub><mark style="color:red;">**educational and personal research purposes only**<mark style="color:red;"></sub><sub><mark style="color:red;">.<mark style="color:red;"></sub>&#x20;

<sub><mark style="color:red;">They are intended to help readers understand, configure, and manage network-level ad blocking using Pi-hole in a controlled, private environment. Be aware that improper configuration of DNS or DHCP settings can lead to network instability, connection issues, or service disruption.<mark style="color:red;"></sub>\ <sub><mark style="color:red;">I do not accept responsibility for any direct or indirect damage, data loss, connectivity problems, security incidents, or legal issues that may arise from following or misapplying the information contained in this guide.<mark style="color:red;"></sub>
{% endhint %}

Pi-hole is an open-source, free program that functions as a DNS sinkhole and is intended to block tracking domains and ads at the network level. It stops unwanted content from loading on any device linked to your network by intercepting DNS requests.&#x20;

Filtering Domain Name System (DNS) queries is how Pi-hole works. The Pi-hole receives a request for a domain's IP address from a device on your network. Pi-hole blocks the connection by refusing to resolve a domain that is on a blocklist.\
To put it simply, Pi-hole filters unwanted traffic before it reaches your browser, serving as a middleman between your devices and the Internet. This method enhances network performance and browsing speed in addition to privacy.

<mark style="color:blue;">**Prerequisites and Hardware**</mark>

To deploy Pi-hole, you will need:

* A **Raspberry Pi** with at least 512MB RAM
* A **microSD card** with an operating system installed. While Pi-hole itself requires little storage, the **read and write speed of the card significantly affects overall performance**.
  * According to the [official Raspberry Pi documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html#recommended-sd-cards), it’s recommended to use **at least 16 GB** for **Raspberry Pi OS Lite**, and **32 GB** for versions with a **GUI**.
* Network connectivity (Ethernet or Wi-Fi).
* The ability to **access and modify your router's settings**.
* *<mark style="color:red;">A basic understanding of how DNS and DHCP work, since Pi-hole will manage part of your network traffic.</mark>*

<mark style="color:blue;">**Initial Setup of the Raspberry Pi**</mark>

We will start by installing the Raspberry Pi Imager tool.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FfHFvYdOVulcm1C71OLcq%2Fimage.png?alt=media&#x26;token=8073c8e1-8e6c-404b-9785-0b855d8975c8" alt=""><figcaption></figcaption></figure>

After installing it, we need to:

1. Select the operating system for our Raspberry model. After selecting the operating system and SD card, we need to set up:
   * Set a hostname (e.g., `pihole`).
   * **Enable SSH** for remote administration.
   * Configure Wi-Fi credentials (if not using Ethernet).
   * Set a username and password.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FMcx9ikDewsTi0DHSBCpy%2Fimage.png?alt=media&#x26;token=3afff360-0213-4a98-993e-bf06b80b52bc" alt=""><figcaption></figcaption></figure>

After that, wait for it to finish. In my case, I used a Raspberry Pi Zero . To find the Raspberry, I scan my local network to see what is assigned to the Raspberry.

<mark style="color:$info;">**`Tip`**</mark><mark style="color:$info;">`: You can use tools like nmap, Fing, or Advanced IP Scanner to quickly identify devices connected to your LAN.`</mark>

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FHUU8ZwPIlm07L6AdlNpp%2Fimage.png?alt=media&#x26;token=5836d8ee-5227-442d-a8aa-538edeccf87a" alt=""><figcaption></figcaption></figure>

Now we need to connect via SSH. To connect via SSH, we can use the prompt, if installed, or we can use PuTTY.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FCTJGYzMi2ZMwFQegAQdy%2Fimage.png?alt=media&#x26;token=29e5f532-9638-4f99-b14f-287b2898ef3a" alt=""><figcaption></figcaption></figure>

Once connected via SSH, we can start installing Pi-hole, which we will use as an ad blocker. We can consult the official [Pi-hole documentation](https://github.com/pi-hole/pi-hole) for details.&#x20;

But before starting the installation, update your Raspberry Pi:

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FKi0gqmyPcTYxfKbCcSHD%2Fimage.png?alt=media&#x26;token=82e01443-896a-4ce0-b246-03fe925aecce" alt=""><figcaption></figcaption></figure>

In our case, we have 21 repositories to update. After updating them, we can begin installing Pi-Hole.&#x20;

<mark style="color:blue;">**Installing Pi-hole**</mark>

There are two ways to install it:

1. An automated command
2. A manual process (explained in the documentation)

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FwqqbMtk5isO32HbZxpta%2Fimage.png?alt=media&#x26;token=d0301d32-6047-4cb9-a068-2b42173c4b1c" alt=""><figcaption></figcaption></figure>

In my case, I will use the automatic command, so I run the command, but:

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2F6lBTnGHw51lZMAWlJFM1%2Fimage.png?alt=media&#x26;token=11e6eda6-3066-4281-8fce-20e3a9fcc4dc" alt=""><figcaption></figcaption></figure>

As you can see, it requires root privileges, so we need to switch users to root using `sudo -i`.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FGqIAeVc1IyvVpLfN1mdA%2Fimage.png?alt=media&#x26;token=6c54f812-80b2-47b6-aaca-0792bd83910b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FY2s5jH1a7nXNe0giiTP4%2Fimage.png?alt=media&#x26;token=da501fa4-b7ae-4690-86f6-e643cb7a472a" alt=""><figcaption></figcaption></figure>

Now it asks us to set a static IP. I will use the same one assigned by the router's DHCP, which is 192.168.1.9, and I will set a reservation on my router. But if you prefer, you can change the DHCP pool on the router and then select an IP from those you exclude from the DHCP. Do as you prefer.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FoBtM1py0zyZv8T3HadgC%2Fimage.png?alt=media&#x26;token=ec3d986a-fc49-47b2-8157-29f057fb2862" alt=""><figcaption></figcaption></figure>

Next, we are asked to select a DNS provider. In my case, I can select CloudFare, but feel free to set whichever one you prefer. Now we are asked to accept whether we want to use the default host list used to block advertisements. I select Yes, but as always, do whatever you prefer.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FoC7uDXSwQ2ANIxDawcyg%2Fimage.png?alt=media&#x26;token=a8e092de-66b5-4877-aa83-2ed157495ec4" alt=""><figcaption></figcaption></figure>

After that page, we are asked if we want to enable log recording. In my case, I select yes because I want to see which sites are blocked.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FDtvAS1ViP0VBUDhIfG14%2Fimage.png?alt=media&#x26;token=fa80b156-ea19-44d2-a7f4-8ba9f9cb4837" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FhB9LaXzVG5Wu7oC5RwKh%2Fimage.png?alt=media&#x26;token=827b443b-caae-4612-8851-727454b6c7e7" alt=""><figcaption></figcaption></figure>

Next, I run a `sudo reboot` command to restart the pi-hole, and after a `pihole -g` command, I synchronize the list on the pihole.

**The “gravity” command downloads all blocklists and updates Pi-hole’s internal database.**

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2F2hhmaxBvKlusbrDjQc8o%2Fimage.png?alt=media&#x26;token=f3051921-9c17-4e83-b6a7-f0de90fad23c" alt=""><figcaption></figcaption></figure>

<mark style="color:blue;">**Adding More Blocklists**</mark>

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2F7vpqLqikp67nlsxOeKj6%2Fimage.png?alt=media&#x26;token=e988386b-69df-4778-9cbe-614ad5b96ab3" alt=""><figcaption></figcaption></figure>

As you can see, the default block lists are installed. Now we can choose to install other block or access lists, we can create different groups with different privileges, and if we are more familiar with it, we can add Regex filters or block an entire domain from the Domains page.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FKdyMtFkXjfEvxFRZaaA9%2Fimage.png?alt=media&#x26;token=97af9f70-7df1-4e1c-8523-aac4aac2f24a" alt=""><figcaption></figcaption></figure>

Now that we have installed Pi-Hole, we can start configuring it, and we will begin by installing another list. I used the lists in this GitHub repository (<https://github.com/hagezi/dns-blocklists>), but as I have always said, feel free to use whichever you prefer.

As we can see on GitHub, there are several versions available.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2F3xIaTMgfzfZV4yRyEowL%2Fimage.png?alt=media&#x26;token=46236c21-2881-4f62-823f-796b7a367596" alt=""><figcaption></figcaption></figure>

I used the Pro version. And select AdBlock for Pi-Hole.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FISXPKRQqwfAZcWOCtbWY%2Fimage.png?alt=media&#x26;token=321cc257-40fd-49c8-ad27-006f777f3ed2" alt=""><figcaption></figcaption></figure>

After selecting the list we want to use, we need to go to Pi-Hole and add the list.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FmwaEZ95DdW90vuFqd0vY%2Fimage.png?alt=media&#x26;token=6cb7bf7a-05d3-47b0-965f-8681ace29fa6" alt=""><figcaption></figcaption></figure>

As you can see, we add the list but do not download it. To download it, we must run the command sudo `pihole -g` and, once done, we will see that the list has been downloaded. After the command, we will see a window like this:

<mark style="color:$info;">**`Tip`**</mark><mark style="color:$info;">`:`</mark>`It’s good practice to occasionally refresh the lists to keep your protection up to date.`

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FJqnFXcTYdECLbnZJCoGb%2Fimage.png?alt=media&#x26;token=c57f654a-4993-4aa2-af54-aca55920ce3d" alt=""><figcaption></figcaption></figure>

<mark style="color:blue;">**Network Configuration**</mark>

Now, before we dive into the configuration, we can set the Pi-Hole's IP as the **primary DNS** on the router so that all traffic passes through the Pi-Hole.&#x20;

If you can't change the DNS, you can disable DHCP on the router and enable DHCP on the Pi-Hole.&#x20;

And if you can't disable DHCP either, I'm sorry, but the only option is to manually configure the DNS on only some devices, also assigning them a static address to pass traffic through the Pi-Hole. This scenario is the same as mine, since the modem is private and provided by the ISP and not freely purchased by me.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FT2MpYF4GkX0XYqmvHlGF%2Fimage.png?alt=media&#x26;token=61ec2e2b-a4d4-4fa6-a112-2be019911790" alt=""><figcaption></figcaption></figure>

<mark style="color:blue;">**Advanced Settings**</mark>

Now that we have explained how to install and configure Pi-Hole, we can move on to the slightly more complicated part.&#x20;

Go to **Settings** and on the right-hand side you will see the basic settings. Click on them and switch to Expert.&#x20;

You will now see other windows such as DHCP Metrics, Cache, DHCP Response, and you can also disable query logging and clear the ARP table.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2FxGiYPTGJRwuWbhROKMyn%2Fimage.png?alt=media&#x26;token=f5948573-7559-4ce5-bfa6-cf089431c61c" alt=""><figcaption></figcaption></figure>

Now if we go to the screen below, so **DNS**, we can see that we can change the DNS provider to use more than one (not recommended), we can also set the interface settings or propagate the settings on the selected port, but before making any changes you need to be sure of what you are doing.&#x20;

We can also change the speed limit, which is the number of requests that the pi-hole receives in a given period of time; by default, the maximum limit is 1000 queries in 60 seconds.

But the most important point I wanted to highlight is **Conditional Forwarding**, so what is it used for and why is it important? Because, as you can see in the Clients section, we would have clients passing through the Pi-Hole, but we would not see the host names, rather the IP addresses or even the MAC addresses, because the Pi-Hole does not perform name resolution. So, to configure it, you need to enter true as the first variable, then the subnet mask in my case (192.168.1.0/24) and then the modem address in my case (192.168.1.1). There is also another optional parameter to add, which is the domain name. In the case of a LAN and a fritz.box modem, you would enter fritz.box.

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2Fgf8eSbFK0LB1FspPqlKo%2Fimage.png?alt=media&#x26;token=120c20ed-ca5a-4814-8e98-c40cb20dfdee" alt=""><figcaption></figcaption></figure>

The DNS screen features the **DHCP** section, you can define:

* DHCP lease and lease time
* Exclusions for specific IP ranges

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2F06eM8fGcz3n7Sj7PFR0p%2Fimage.png?alt=media&#x26;token=bab2226f-18ac-49c4-b916-2ee741c7b17b" alt=""><figcaption></figcaption></figure>

Under **Web Interface - API Settings**, you can:

* Enable 2FA for extra security
* Set a custom admin password
* Change the web interface theme (light/dark)

<figure><img src="https://2833470610-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxEQmpwmdm3I8FZ925fn8%2Fuploads%2F6xkT9Ed2OtnrEGcyxhYF%2Fimage.png?alt=media&#x26;token=40e5149a-f6ea-4ef6-a690-35a4ad681493" alt=""><figcaption></figcaption></figure>

There are a few other configuration tabs, but these relate to optional settings that you can view on your own.\
For example, you can integrate Pi-hole with Unbound or DNSCrypt for encrypted DNS queries, further improving privacy.\
You may also install a lightweight monitoring tool like Grafana or Netdata to visualize DNS traffic and performance over time.
