Athulya
Athulya
Just a small town girl livin' in a lonely world.

Pi-Hole

Pi-Hole

Introduction

Why do you need a Pi-hole? Well aren’t you just tired of having ads all the time and needing to use an ad-blocker that may or may not be selling your data to organizations? If I could describe to you what a Pi-hole is in two words it would be “better ad-blocker”. Before getting into the details of how to set one up, I will explain how it works.

Network traffic with and without Pi-hole

Okay, this might look really overwhelming but trust me once you setup the Pi-hole, it will all come together. Right now, our network is pretty basic. Any time your computer wants to talk to a website, it has to ask your router first. All we are doing is adding the Pi-hole, so that your computer asks it instead. The router is still needed to connect to the internet (sorry if you thought this was free internet).

Setting Up Pi

What was included in my box?

All you need is the Pi Zero W, 5V Power supply, and 8GB SD Card

Getting the dev kit is recommended if you want to do other projects on your Pi Zero.

  1. The first step is to format the SD card that was included. It may already have files and an OS system included, so it is always good to start with formatting your SD card.

    1. Insert the SD card on your computer.

    2. If you don’t have the format option on your computer:

      1. Download the Formatting Tool for Windows.
      2. Mac Formatter

      SD Formatting

    3. Select the location of your SD card.
    4. Choose Overwrite format and give it a name.
  2. Now for our Pi, we need to choose a lightweight OS that doesn’t take up too much space, yet it does the job it needs to.

    1. Choosing an OS system.
  3. I chose DietPi because I don’t need a desktop environment.

  4. A tool I use to write disk images is Etcher, you can download it here.

    1. Unzip DietPi.7z file using 7-zip (for Windows).
      Writing Image
    2. Open Etcher and drag the DietPi.img file, then choose the SD card location, and hit FLASH!
  5. If Etcher ejects your SD card, unplug and replug the SD card.

Configure OS

  1. Setup the Pi so that we can ssh into it from our computer.

    1. Modify the dietpi.txt file on the SD card.
    1
    2
    
    AUTO_SETUP_NET_ETHERNET_ENABLED=0 # {Not mandatory to change it to 0}
    AUTO_SETUP_NET_WIFI_ENABLED=1
    
    1. Modify the dietpi-wifi.txt on the SD card if you are using WiFi .
    1
    2
    
    aWIFI_SSID[0]= 'WIFI_NAME'
    aWIFI_KEY[0]= 'WIFI_PASSWORD'
    
    1. By default ssh should be enabled in DietPi.
  2. Eject and remove the SD card.

Router Settings

  1. Insert the SD card into your Pi and power it up.

  2. If you didn’t set a static IP for your Pi, we need to find which IP to connect to.

    1. The steps below may vary depending on the router dashboard.

    2. Access your router dashboard {usually 192.168.0.1}.

      1
      
      ipconfig | findstr "Default Gateway" # This will show your router IP
      
    3. Click on the Basic tab at the top of the page.

    4. View the Connected Devices.

    5. Your hostname which is DietPi and the IP should be there.

      1. If it is not, power off your Pi, re-insert your SD card into your computer and look at the WiFi configurations.
  3. Since you do not want the router to assign a new IP to your Pi all the time, we will set a static IP at the router level.

    1. On the same page for your router dashboard (Basic tab).
    2. Click on DHCP Reservation.
    3. Find the hostame/IP and click on add.
    4. Now this IP has been reserved solely for Pi connectivity.

    Later on, I will explain why we set a static IP at the router level.

Let’s SSH-it

  1. SSH into your Pi using MobaXTerm or any command terminal with SSH installed.

  2. 1
    2
    
    ssh root@<Pi_IP>
    Password: dietpi
    
  3. Now it will automatically look for updates and apply them.

  4. Change the root and user passwords as instructed {make sure to remember them}.

  5. You can install and uninstall software as you wish or do it later after everything is updated/upgraded

Install Pi-hole

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

    Installation of Pi-hole

    Installation of Pi-hole

  2. Choose your DNS provider – default Google (8.8.8.8). I like Cloudflare as well (1.1.1.1).

  3. Ad block lists - Keep it as it is and we will add more if we need to.

  4. IP reserve - already configured it so that this IP is static.

    1
    2
    3
    
    Few things to keep in mind:
     ** What happens when we change our router (eg.new Internet provider)? We will have to set the static IP again and re-configure
     ** The router has a set block of start IPs and end IPs. By choosing an IP whose last digit is close to 2 or close to 254, there is more of a guarantee that we won't have to keep reserving an IP everytime we switch Internet providers
    
  5. Web Admin Interface - keep the default.

  6. Log Queries - default answer.

  7. Now Pi-hole is setup, but there is one final step that we need to complete for the whole network flow to work.

Router Configuration Again

  1. Head over to your router dashboard one last time.

  2. Go to the Basic tab.

  3. Click the DNS tab and set it to Manual.

  4. Add your Pi-hole IP to DNS1.

  5. Now your network flow looks like the image below:

    Something to keep in mind: The first time a device connects to your WiFi, the router will push down the configurations inlcuding the DNS we set above. Now, when the device makes a DNS request, it will talk directly to the Pi-hole.

  6. Restart your router
  7. Everything should be good to go! Visit http://pi.hole and have fun exploring

comments powered by Disqus