How to setup Pi-hole with Raspberry Pi Zero W?

After finding out how much it costs in the US to purchase the Raspberry Pi Zero W and combined with my longstanding desire to tinker and get my hands on a Raspberry Pi, even though I had no idea what I was gonna do with it, I ordered one from Argon40. With shipping, it added up to around S$20.

As I am usually quite annoyed by the rampant advertising encountered everywhere online, one of the first things I’ll download on my new devices (aside from the browser) is the amazing uBlock Origin. However, my family aren’t as savvy and while I do try to help them whenever I can, it can be quite cumbersome to do so for all their devices.

Naturally, the first project which came to mind is the Pi-hole, a network-level solution designed to block advertisements and trackers. I’ve gone through a number of tutorials but most of them are by the Raspberry Pi accessories sellers themselves which left me uncertain if I actually do need a certain component to get my Pi0 working.

What you really need:

Here’s my personal experience in the form of a simple, straightforward tutorial:

  1. Download and install Etcher
  2. Download the latest Raspbian Stretch Lite
  3. Insert and flash the microSD using Etcher. After the process is completed successfully, the microSD will be renamed boot and you will be able to view its system files.
  4. Create the file `/boot/wpa_supplicant.conf`. Replace YOURWIFINETWORKNAME and YOURWIFIPASSWORD appropriately.

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=US

    network={
    ssid="YOURWIFINETWORKNAME"
    psk="YOURWIFIPASSWORD"
    scan_ssid=1
    }

  5. Edit /boot/config.txt. Add the following to the end of the file.

    # Enable UART
    enable_uart=1

  6. Create /boot/ssh. Leave it blank.
  7. Eject the microSD safely and insert it into your Pi0. Connect the Pi0 PWR IN port to the router USB port. That will be serving as the Pi0’s power source.
  8. Wait for at least 2 minutes to allow the OS to boot. You can verify it’s working from the blinking green LED light on the Pi0.
  9. You can now SSH into your Pi0. The default password is raspberry.

    ssh [email protected]

  10. Run the following commands to update the system and configure your Pi0. Probably a good idea to change the password.

    sudo apt-get update
    sudo apt-get upgrade
    sudo raspi-config

  11. Install Pi-hole

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

  12. The installer will ask a bunch of questions and it’s mostly fine to go with the defaults for now. If you’d like to take it a step further to enhance your privacy, you can follow this guide after to run your own recursive DNS server.
  13. It’ll probably take a while but once the installation finishes, take note of the web admin login URL and default password. You can change it immediately with the following command:

    pihole -a -p

  14. If you’d like to access your admin panel via the `http://pi.hole/admin` URL instead of the Pi-hole’s IP address, edit /etc/hosts:

    127.0.0.1 localhost
    [replace with Pi-hole's IP] pi.hole [replace with the actual hostname of the machine running Pi-hole]

  15. Login to your home network router’s admin panel (probably via 192.168.1.1.). Update the DNS 1+2 to use Pi-hole’s IP. I’m using Linksys’s and the settings can be found under Connectivity –> Local Network –> DHCP Server –> Static DNS. Save.
  16. Reboot any device connected to your network.
  17. That’s it. You should now have Pi-hole running on your network.
  18. While not recommmended by the developers, I run the following script via cron to keep my Pi-hole and the Gravity list updated:

    #!/bin/sh
    LOG_FILE=/var/log/update_pihole.log

    echo "Update started" >> $LOG_FILE
    date >> $LOG_FILE
    pihole -up >> $LOG_FILE
    pihole-g >> $LOG_FILE

    exit 0

  19. If you need to temporarily disable Pi-hole for whatever reason, you can either do so via the administrative panel or the API:

    http://pi.hole/admin/api.php?disable=300&auth=[YOUR API AUTH KEY]

    You can retrieve the API key by logging into the administrative panel, navigate to Settings -> API/Web Interface and click the ‘Show API token’ button.

So simple!

2019-03-20

index