How to Use a Raspberry Pi to Block Ads on Your Wireless Network With Pi-hole

Ricky Takkar
Created on June 4, 2020

Here’s an overview of the Pi-hole from their official website.


  • One of the main incentives for me to set up Pi-Hole on my network was to block YouTube ads on devices like iPhones and iPads. However, I found that while ads were blocked everywhere – it was impossible to block ads on YouTube without blocking the videos, too. The problem is that while ads on most other platforms are hosted on domains that are separate from the content, YouTube, of course, typically hosts ads on the same servers as its content (ad-free YouTube requires you to pay for YouTube Premium). Similarly, while I don’t have Instagram myself, I’ve been informed that Instagram ads, like the ones on YouTube, don’t fall prey to the Pi-Hole.

  • On a separate note, most guides are either based on wired network connections for setting up Pi-Hole, or, wireless ones. For the ones that focus on the latter, their network configuration steps are also written with the assumption that the Pi and your computer can SSH wirelessly over your network once you modify the MicroSD contents after flashing on your computer. I was never able to find my Pi with SSH from my computer despite following those steps to a tee. What eventually worked for me, and what this guide implements, was to initially SSH over USB to get the network settings fixed on my Pi.


  • Raspberry Pi (I used the Zero W model)

  • 2A power supply (1A will work with Pi Zero W)

  • Micro-USB cable (ensure that it’s capable of data transfer)

  • Another computer, apart from the Pi (while not necessary, I found it much easier to use my laptop for debugging and acquiring important information pertaining to the setup rather than connecting a monitor, keyboard and mouse to the Pi – this guide is written assuming you have another computer)

  • Functional wireless network (some Pi models, like the Zero W, don’t work with 5GHz bands)

  • MicroSD card (I recommend a minimum of 8GB based on the OS, and additional files)

  • SSH client (I like PuTTY)

  • Bonjour for Windows (if your computer is Windows)


  1. Flash the latest Raspberry Pi OS (formerly known as “Raspbian”) to the MicroSD card with your computer

    1. Find the OS here (I used the lite version of the OS to save space and boost performance since Pi-Hole is a one-time setup and can be done through the command line)

    2. Use a flashing tool like balenaEtcher

    3. Flashing the MicroSD will format it before installing the OS

  2. Re-plug the MicroSD card into your computer and get it ready for the Pi

    1. Once the flash is complete, and you re-plug the MicroSD in your computer, you may get an error message that suggests to reformat your MicroSD – ignore this alert

    2. Find the boot directory on your MicroSD card and do the following in there:

      1. Create a file named ssh (leave it empty – this will tell the Pi to enable SSH during boot so that you can communicate with it from your computer) and ensure it’s not saved with a .txt extension

      2. Open config.txt and append this to the bottom:

      3. Open cmdline.txt and append this between rootwait and whatever code there is after it, if any:
        Note that there should be whitespace after rootwait which precedes the appended line and whitespace after the last character of the appended line and the code after it, in case there is anyy

  3. Boot the Pi with the MicroSD card

    1. Insert the MicroSD card into the Pi

    2. Connect the Pi to your computer via USB; the computer powers your Pi

    3. Once connected, wait about 2 minutes for the Pi to boot up.

  4. SSH into Pi via USB

    1. Run the following commands in your terminal:
      ssh-keygen -R raspberrypi.local
      ssh pi@raspberrypi.local

    2. The default username for a Raspberry Pi is pi and the default password is raspberry

  5. Connect the Pi to your WiFi

    1. While SSH’d into the Pi via USB, run the following command to set up a wireless network connection quick by following on-screen commands:
      sudo raspi-config

    2. Ensure that you’re connected to a wireless network by running the command:
      ifconfig wlan0
      If this command returns an address next to the “inet” field, you’ve successfully connected to your wireless networkk

  6. SSH into Pi via WiFi

    1. Disconnect your Pi from your computer and set it up wherever you would like to as its final location – if the steps above were successful, you’ll only need to connect to it wirelessly anyway

    2. Once you power your Pi through a wall socket, wait another 2 minutes to let it boot up

    3. In your computer’s terminal, type the following command:
      ssh pi@raspberrypi.local
      If you logged in successfully, you’ll notice the effective ID for the shell change into that of the Pii Install Pi-Hole

  7. Run the following command to install Pi-Hole:
    curl -sSL | bash
    A series of automated tasks will take place before you are asked to configure certain installation settings with your keyboard

    1. One of those settings is to pick a DNS provider, I use Cloudflare

    2. You will be shown an option to continue with the automatically assigned IP address or to assign a static one. The most robust solution is to assign a static IP address which can be done by playing around with your router settings. If you have no idea how to do this, continue with the default – we can always change it later.

    3. Make sure you press “yes” when asked to install the “web admin interface”

    4. When the installation is complete, you will see a window that provides you with the address being used by the Pi-Hole, the admin webpage address and its password. Make sure you save this information.

    5. Reboot your Pi via SSH by running:
      sudo reboot

    6. Now that Pi-Hole is installed, and you’re connected via SSH wirelessly, ensure that Pi-Hole installed successfully by running:
      pihole -h

  8. Make your devices use Pi-Hole

    1. Now that Pi-Hole is running on your Pi, you’ve got 2 choices for making your devices use Pi-Hole to block ads:

      1. Choice 1: You can make it so that every single device connected to the same wireless network as the Pi-Hole automatically uses it to block ads. To do this, just set your router’s DNS address to the Pi-Hole’s IP address

      2. Choice 2: You can manually set each device to use the Pi-Hole as long as its on the same wireless network

    2. I prefer choice 2 to prevent issues with my device’s internet connection in case something goes wrong with the Pi.

    3. You can manually set whatever device connected to the same network as Pi-Hole to use the Pi-Hole for ad-blocking by simply replacing the DNS address in the device’s network settings with the IP address of the Pi-Hole.

    4. Once that’s done, your device will automatically use the Pi-Hole to block internet ads as long as you’re on the same network