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”.
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!
Set it up!
- 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.
- Get a microSD Card. 16GB are more than enough.
- 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 asRaspberry Pi OS (Legacy, 32-bit)
and your SD card for Storage.
- 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.)
Click
Edit Settings
and set a hostname
(not really necessary, but why not), login 👤username
and 🔑password
, configure your WLAN access
and… …make sure to enable
SSH
under the Services
tab!- Now choose
Save
andYes
and let it write everything to the SD card.
- Once done, put the SD card into your Pi Zero and connect it to power!
- 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 itsSettings/IP Settings
to ✅Fixed IP Address
)
- 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)
- 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, pickwlan0
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.
- In the end you get a screen like this where you want to note down the password for the web interface
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.
- 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)
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! 😌👍
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!