Death to all Advertising! (On my local network)

date
Mar 23, 2024
type
Post
year
slug
pi-hole-pi-zero
status
Published
tags
Adblock
Raspberry Pi
SBC
summary
How to set up network-wide ad blocking with pi-hole and a Raspberry Pi Zero W!

Introductory Rant

You might have noticed that the world wide web is full of ads. On some sites it’s hard to find the actual content between all the ads. So you add an adblocker to your browser, but then countless websites pop up windows telling you to disable your adblocker if you want to access their content. And in any case: you still see more than enough ads in apps on your phone. Ads use a lot of bandwidth and energy and most importantly: they blur your focus and waste your time.
Well, no more! Enter Pi-hole with its catchy slogan “Network-Wide Ad Blocking”.
1671 queries (10% of all queries) blocked over the first few hours of use!1671 queries (10% of all queries) blocked over the first few hours of use!
1671 queries (10% of all queries) blocked over the first few hours of use!
Pi-HolePi-Hole
Pi-Hole

Network-Wide Ad Blocking

It’s actually quite simple: Pi-hole is a DNS server with a well-curated block-list.
Every time anything on your network wants to access a specific domain, a call goes out to a DNS server that looks up the domain name and returns the IP address for that domain. Pi-hole acts as your DNS server, but knows a long list of domains used for advertising and simply throws out those requests, so no advertising content makes it back to your device.
And it’s fairly simple to set up! I installed it on a Raspberry Pi Zero W (a $15 single-board-computer), then changed one setting on my router to force the entire local network to use pi-hole as its DNS server, done!
Raspberry Pi Zero W - a 6.5cm x 3cm big computer that can be powered by an old micro-USB phone charger.Raspberry Pi Zero W - a 6.5cm x 3cm big computer that can be powered by an old micro-USB phone charger.
Raspberry Pi Zero W - a 6.5cm x 3cm big computer that can be powered by an old micro-USB phone charger.

Set it up!

  1. Get a Raspberry Pi Zero 2 W (make sure it has the W - that means it has WiFi. Otherwise you need a micro USB to RJ45 dongle to connect it to the network) I got mine from Mouser, but lots of places sell it. And one more note: I’m using the first gen one, but if you don’t have one yet, get the new one - it costs the same and is 3x as fast.
    1. notion imagenotion image
  1. Get a microSD Card. 16GB are more than enough.
    1. notion imagenotion image
  1. Get the Raspberry Pi imager and use it to prepare the microSD card by choosing Raspberry Pi Zero 2 W (or whatever model you’re using), as well as Raspberry Pi OS (Legacy, 32-bit) and your SD card for Storage.
    1. notion imagenotion image
  1. It asks if you would like to customize your OS, and oh yes you do. But first: EDIT SETTINGS to choose the exact customization options! (This is great, because then we won’t have to set all of this up later on the device.)
    1. notion imagenotion image
      Click Edit Settings and set a hostname (not really necessary, but why not), login 👤username and 🔑password, configure your WLAN access and…
      notion imagenotion image
      …make sure to enable SSH under the Services tab!
      notion imagenotion image
  1. Now choose Save and Yes and let it write everything to the SD card.
  1. Once done, put the SD card into your Pi Zero and connect it to power!
  1. Wait until you see it pop up in your router software and give it a static IP address (Different for every router - I have a Ubiquiti Dream Machine Pro where I simply go to Topology, then find the “pihole” device and set its Settings/IP Settings to ✅Fixed IP Address)
  1. SSH into the pi zero $ ssh yourUsername@192.168.1.211 (use the 👤username you picked in step 4 and the IP address of your Pi Zero, which you found in step 7), then enter the 🔑password (you also picked this in step 4) - this way you can set everything up from your PC/Mac/Linux desktop and don’t even need to attach a screen and keyboard to the Pi Zero at all. (But you could of course hook up a Monitor and a keyboard and do all of this in a terminal directly on the device instead)
    1. Successfully ssh’d into the Pi Zero. Now we’re on the Pi Zero’s command prompt, ready to install stuff!Successfully ssh’d into the Pi Zero. Now we’re on the Pi Zero’s command prompt, ready to install stuff!
      Successfully ssh’d into the Pi Zero. Now we’re on the Pi Zero’s command prompt, ready to install stuff!
  1. So let’s ⬇️ install pi-hole on the Pi Zero! There’s a one-step automated install available, just enter this line: $ curl -sSL https://install.pi-hole.net | bash and watch it install! (https://github.com/pi-hole/pi-hole/#one-step-automated-install) If it asks you for an interface, pick wlan0 to use WiFi, if it asks for an upstream DNS provider pick Google or whoever you want (that’s where it will forward the DNS requests that aren’t filtered out). Default blocklist is fine, just stick to the defaults for everything else.
    1. notion imagenotion image
  1. In the end you get a screen like this where you want to note down the password for the web interface
    1. notion imagenotion image
👉
INTERMISSION! At this point Pi-hole is ready to go! 👍 You could now enter it’s IP address as the DNS server on each individual of your devices, but we’re going to go on and set it as the DNS server for the entire local network instead.
  1. Now we’ll set pi-hole as the DNS server for the 📶 entire local network! Again, this is different for every router, but in essence you’re looking for the place where you can set the Primary DNS server for your WAN. (On my Ubiquiti Dream Machine Pro it’s here: Settings/Internet/WAN1 - Advanced: Set to “Manual”, IPv4 Config > DNS Server - uncheck “Auto” and enter the Pi-hole’s IP address as the Primary Server)
    1. This is how I set the DNS server for the entire local network on the UDM Pro.This is how I set the DNS server for the entire local network on the UDM Pro.
      This is how I set the DNS server for the entire local network on the UDM Pro.
💡
Some people set up a second Pi Zero as a failsafe and enter that one as the Secondary DNS. Because if the one goes down you’ve got no DNS until it’s back up!
⚠️
Do write down the IP address of the Pi Zero (to check if it’s down) and the IP address of your router (to change back to a standard DNS server, should you ever need to!).

And Done!

Now the entire local network should use pi-hole for all its DNS needs and almost all advertising should disappear or leave nothing but empty boxes behind! Ah, peace and quiet at last! 😌👍
notion imagenotion image
Once done, go to http://pi.hole/admin (your pi-hole will grab that DNS-lookup and point you at its own IP address) for some nice statistics about what it’s blocking!
notion imagenotion image

Leave a comment