Tired of intrusive ads slowing down your browsing and compromising your privacy? Want a single solution to block ads across all devices on your network? This comprehensive guide will walk you through setting up Pi-hole on a Raspberry Pi Zero 2 W, providing network-wide ad blocking for a cleaner, faster, and more secure online experience.

What is Pi-hole?

Pi-hole is a powerful, open-source network-wide ad blocker that acts as a DNS (Domain Name System) sinkhole. Think of it as a gatekeeper for your internet traffic. When a device on your network tries to access a website or resource, it first asks Pi-hole for the address. Pi-hole consults its list of known ad servers and trackers. If a request is for a blocked domain, Pi-hole simply refuses to provide the address, effectively preventing the ad from loading. This happens at the DNS level, meaning it works across all applications and devices, including smart TVs, smartphones, tablets, game consoles, and computers.

Key Benefits of Using Pi-hole:

  • Network-Wide Ad Blocking: Blocks ads on all devices connected to your network without requiring individual software installations or browser extensions.
  • Improved Browsing Speed: By blocking ads and trackers, Pi-hole reduces the amount of data that needs to be downloaded, resulting in faster page load times.
  • Enhanced Privacy: Protects your privacy by blocking trackers that collect data about your online activity.
  • Reduced Data Usage: Blocking ads can significantly reduce your overall data consumption, especially beneficial for those with limited data plans.
  • Centralized Management: Manage your ad blocking settings from a single, user-friendly web interface.
  • Open Source and Free: Pi-hole is free to use and open-source, meaning you have complete control over your ad blocking solution.

Why Use a Raspberry Pi Zero 2 W?

The Raspberry Pi Zero 2 W is an excellent and cost-effective choice for running Pi-hole. Here’s why:

  • Low Power Consumption: The Zero 2 W consumes very little power, allowing it to run 24/7 without significantly impacting your electricity bill.
  • Small Size: Its compact form factor allows for discreet placement anywhere in your home.
  • Built-in Wi-Fi: The integrated Wi-Fi connectivity simplifies setup and eliminates the need for an Ethernet cable (although Ethernet via USB adapter is an option for increased stability).
  • Sufficient Processing Power: The Raspberry Pi Zero 2 W has enough processing power to handle DNS requests for a small to medium-sized home network.

Alternative Raspberry Pi Models:

While this guide focuses on the Zero 2 W, Pi-hole can also be installed on other Raspberry Pi models, such as the Raspberry Pi 3, 3B+, 4, or 5. These models offer more processing power and memory, which may be beneficial for larger networks or if you plan to run other applications alongside Pi-hole.

Prerequisites

Before you begin, gather the following:

  • Raspberry Pi Zero 2 W: (or another Raspberry Pi model)
  • MicroSD Card (8GB or larger): A reliable microSD card is crucial for storing the operating system and Pi-hole software. Consider a high-endurance card for optimal performance and longevity.
  • MicroSD Card Reader/Writer: Used to flash the operating system image onto the microSD card.
  • Power Supply: A 5V micro USB power supply specifically designed for Raspberry Pi is recommended. Using an underpowered supply can lead to instability.
  • Internet Connection: A stable internet connection is required for downloading the operating system, Pi-hole software, and updating blocklists.
  • Computer: Used to download the necessary software and configure the Raspberry Pi.
  • (Optional) USB Ethernet Adapter: If you prefer a wired network connection for increased stability.

Step-by-Step Guide

1. Install Raspberry Pi OS

The first step is to install Raspberry Pi OS, the recommended operating system for Raspberry Pi.

  1. Download Raspberry Pi Imager: Download the latest version of the Raspberry Pi Imager from the official Raspberry Pi website: https://www.raspberrypi.com/software/
  2. Install and Run Imager: Install the downloaded application on your computer.
  3. Choose OS and SD Card:
    • Open Raspberry Pi Imager.
    • Click “Choose OS”. For Pi-hole, the “Raspberry Pi OS Lite (64-bit)” version is recommended as it’s a minimal installation without a desktop environment, reducing resource usage. If you prefer a graphical interface, you can choose the standard “Raspberry Pi OS (64-bit)” version, but be aware that it will consume more resources.
    • Click “Choose Storage” and select your microSD card.
  4. Edit settings: (Important for Headless Setup) Before writing the image, click the cog icon to access advanced settings. Here you can:
    • Set the hostname (e.g., pihole).
    • Enable SSH.
    • Configure the username and password for the pi user. Crucially, change the default password!
    • Configure Wi-Fi by entering your network SSID and password.
  5. Write the Image: Click “Write” to flash the OS to the microSD card. Warning: This process will erase all existing data on the card! Confirm that you have selected the correct microSD card before proceeding.

2. Configure SSH and Wi-Fi (Optional, Only If You Skipped Step 4 Above)

If you didn’t configure SSH and Wi-Fi using the Raspberry Pi Imager’s advanced settings in the previous step, you can manually configure them after flashing the OS. This is necessary for a headless setup (accessing the Pi without a monitor or keyboard).

  1. Enable SSH: After the image is written, safely eject and reinsert the microSD card into your computer. Open the boot partition. Create an empty file named ssh (with no extension). This can be done using a text editor or via the command line:

     touch /Volumes/boot/ssh  # Replace /Volumes/boot with the actual path to your boot partition if necessary
    
  2. Configure Wi-Fi: In the boot partition, create a file named wpa_supplicant.conf and add the following content, replacing YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with your actual Wi-Fi network name and password:

     country=GB  # Replace with your country code (e.g., GB, CA, DE)
     ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
     update_config=1
    
     network={
          ssid="YOUR_WIFI_SSID"
          psk="YOUR_WIFI_PASSWORD"
     }
    

    Important: Ensure that the country= setting is correct for your location. A missing or incorrect country code can prevent Wi-Fi from working properly.

3. Boot the Raspberry Pi and Connect via SSH

Insert the microSD card into the Raspberry Pi and connect the power supply. The Pi should boot up automatically.

  1. Find the Raspberry Pi’s IP Address: You need to determine the IP address assigned to your Raspberry Pi by your router. There are several ways to do this:
    • Router Administration Panel: Log in to your router’s web interface (usually by typing its IP address into a web browser). Look for a list of connected devices or a DHCP client list. The Raspberry Pi should be listed with its hostname (if you set one in the Imager) or a generic name like “raspberrypi”.
    • Network Scanning Tool: Use a network scanning tool like nmap (available for most operating systems) or a mobile app like “Fing” to scan your network and identify the Raspberry Pi.
  2. Connect via SSH: Once you have the IP address, use an SSH client (PuTTY on Windows, or the built-in terminal on macOS/Linux) to connect to the Raspberry Pi:

     ssh pi@<your_raspberry_pi_ip_address>
    

    If you are using the default username and password, you’ll be prompted to change the password upon first login. Do this immediately for security reasons!

4. Install Pi-hole

Now that you’re connected to the Raspberry Pi via SSH, it’s time to install Pi-hole.

  1. Update Package Lists and Upgrade Existing Packages: Before installing Pi-hole, it’s good practice to update the package lists and upgrade any existing packages to ensure you have the latest versions:

     sudo apt update
     sudo apt upgrade -y  # The -y flag automatically answers "yes" to any prompts
    
  2. Install Pi-hole: Use the following command to download and run the Pi-hole installer:

     curl -sSL https://install.pi-hole.net | bash
    

    This command downloads a script and executes it. The installer will guide you through the setup process. Pay close attention to the prompts and make the following choices:

    • Interface: Choose your network interface (usually wlan0 for Wi-Fi or eth0 for Ethernet).
    • Static IP Address: This is crucial! Select the option to configure a static IP address for your Raspberry Pi. The installer will guide you through the process. Choose an IP address outside of your router’s DHCP range. For example, if your router assigns IP addresses from 192.168.1.100 to 192.168.1.200, choose an address like 192.168.1.50. Note: ensure this static IP is outside your DHCP range or you may have IP conflicts. This can also set on the router side to make it static.
    • Gateway: Enter the IP address of your router (usually something like 192.168.1.1).
    • DNS Provider: Choose a DNS provider. Cloudflare (1.1.1.1 and 1.0.0.1) is a good choice for privacy and speed. You can also choose other providers like Google (8.8.8.8 and 8.8.4.4) or OpenDNS.
    • Web Admin Interface: Enable the web admin interface. This is essential for managing Pi-hole.
    • Logging: Enable logging for query analysis. This allows you to see which domains are being blocked and monitor Pi-hole’s performance.
    • Agree to the warning: Agree to the warning, because you will be using a static IP (as you should be!).

    At the end of the installation, the installer will display the IP address of your Pi-hole server and the automatically generated password for the web admin interface. Make a note of these!

  3. Change the Web Admin Password: The automatically generated password is often complex and difficult to remember. It’s highly recommended to change it to something more manageable:

     sudo pihole -a -p
    

    This command will prompt you to enter and confirm a new password for the web admin interface.

5. Configure Your Devices to Use Pi-hole

After the installation is complete, you need to tell your devices to use your Raspberry Pi as their DNS server. There are two main ways to do this:

Option 1: Router Configuration

This is the easiest way to configure all devices on your network at once. However, the exact steps vary depending on your router’s make and model.

  1. Access Your Router’s Administration Panel: Open a web browser and enter your router’s IP address (usually 192.168.1.1 or 192.168.0.1). Log in using your router’s username and password (often found on a sticker on the router itself).
  2. Locate DNS Settings: Look for DNS settings, often found in the WAN, Internet, or DHCP settings sections.
  3. Enter Pi-hole’s IP Address: Enter the static IP address of your Raspberry Pi as the primary DNS server.
  4. Secondary DNS Server (Optional): You can leave the secondary DNS server blank, or set it to another public DNS server like 8.8.8.8 (Google) or 1.1.1.1 (Cloudflare) for redundancy. However, keep in mind that if the primary DNS server (Pi-hole) is unavailable, your devices will use the secondary DNS server and bypass ad blocking.
  5. Save Changes and Reboot Router: Save the changes and reboot your router. This will force all connected devices to renew their IP addresses and start using Pi-hole as their DNS server.

Option 2: Individual Device Configuration (Recommended)

This method allows you to configure DNS settings on each device individually. The steps vary depending on the operating system:

  • Windows:
    1. Go to Network and Sharing Center.
    2. Click on your network connection.
    3. Select “Properties”.
    4. Choose “Internet Protocol Version 4 (TCP/IPv4)” and click “Properties”.
    5. Select “Use the following DNS server addresses”.
    6. Enter the Raspberry Pi’s IP address as the “Preferred DNS server”.
    7. You can enter a secondary DNS server in the “Alternate DNS server” field (optional).
    8. Click “OK” and close the windows.
  • macOS:
    1. Go to System Preferences.
    2. Click on “Network”.
    3. Select your network interface (e.g., Wi-Fi or Ethernet).
    4. Click “Advanced”.
    5. Go to the “DNS” tab.
    6. Click the “+” button to add a new DNS server.
    7. Enter the Raspberry Pi’s IP address.
    8. Click “OK” and “Apply”.
  • Android/iOS:
    1. Go to your Wi-Fi settings.
    2. Select your network.
    3. Modify the DNS settings (this often requires selecting a “Static” IP configuration).
    4. Enter the Raspberry Pi’s IP address as the DNS server.

Testing the Configuration:

After configuring your devices, you can test if Pi-hole is working correctly by visiting a website known for displaying ads (e.g., a news website). If the ads are blocked, Pi-hole is working! You can also check the Pi-hole web interface to see the number of queries being blocked.

6. Access the Pi-hole Web Interface

Open a web browser and navigate to http://<your_raspberry_pi_ip_address>/admin. Replace <your_raspberry_pi_ip_address> with the actual IP address of your Raspberry Pi.

You’ll be greeted by the Pi-hole web interface, where you can:

  • View Statistics: See real-time data on the number of queries, blocked domains, and top blocked domains.
  • Manage Blocklists: Add, remove, and update blocklists to customize your ad blocking.
  • Whitelist Domains: If a website is being blocked incorrectly, you can whitelist it to allow it to load.
  • Configure Settings: Adjust various Pi-hole settings, such as DNS providers and logging options.
  • View Query Log: See a detailed log of all DNS queries processed by Pi-hole.

7. Adding Additional Blocklists

Pi-hole comes with a default blocklist, but you can significantly improve its effectiveness by adding more lists. There are many excellent blocklist resources available online.

  1. Find Reputable Blocklists: A good resource for blocklists is: https://github.com/hagezi/dns-blocklists?tab=readme-ov-file#pro. This repository provides a curated list of blocklists with different focuses and levels of aggressiveness. Other good resources can be found by searching online for “Pi-hole blocklists”. Be cautious when adding blocklists from unknown sources, as they may contain malicious domains.
  2. Add Blocklists in the Web Interface:
    • Go to the Pi-hole web interface (http://<your_raspberry_pi_ip_address>/admin).
    • Click on “lists” in the left-hand menu.
    • Enter the URL of the blocklist in the “Address” field. Example: https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/domains/pro.txt.
    • Click “Add”.
  3. Update Gravity: After adding new blocklists, you need to update Pi-hole’s gravity database to incorporate the new lists.
    • Go to “Tools” in the left-hand menu.
    • Click “Update Gravity”. This process may take a few minutes.

Choosing the Right Blocklists:

  • Start with Recommended Lists: Begin with a few well-maintained and widely recommended blocklists.
  • Consider Your Needs: Choose blocklists that align with your specific needs and privacy concerns. For example, you might want to add lists that focus on blocking trackers or malicious domains.
  • Monitor Performance: After adding new blocklists, monitor Pi-hole’s performance and query log to ensure that websites are loading correctly and that there are no false positives (legitimate websites being blocked).
  • Adjust as Needed: If you encounter issues, you can remove or disable blocklists to troubleshoot the problem.

Conclusion

Congratulations! You’ve successfully set up Pi-hole on a Raspberry Pi Zero 2 W. You should now enjoy a cleaner, faster, and more private browsing experience across all your devices. Remember to regularly update your blocklists and monitor Pi-hole’s performance to maintain optimal ad blocking. By taking control of your network’s DNS, you’ve significantly enhanced your online privacy and security. Enjoy ad-free browsing!