Setting up a Rasberry Pi Zero W as an Ad Blocker

Alan
4 min readOct 8, 2021

--

Photo by https://mythemeshop.com/blog/best-ad-blockers/

Hello, this is one of many tutorials you can find online on how to set up a Rasberry Pi Zero W as an ad blocker for your home network using Pi-hole. I am a big fan of user privacy while on the internet and do not like being tracked by Google, Facebook or any other big data companies. I hope this tutorial is simple and helpful, please reach out if you have any questions.

Items required:

  • Rasberry Pi (I used a Rasberry Pi Zero W bought from Amazon here)
    * Includes power adapter and other accessories
  • Micro SD Card (I bought a 32GB 2 pack on amazon here)
  • USB ethernet adapter

How to download Rasberry Pi OS Lite:

  1. Download Raspberry Pi OS Lite, unzip until you have a .imgfile
  2. Insert SD card into your computer/laptop
  3. Download this app to flash the .imgfile onto your SD card.
  4. The SD card will now be renamed to boot
  5. Enable ssh by creating an ssh file in the SD card
  6. touch /Volumes/boot/ssh
Adding ssh file to Pi OS
  1. Eject the boot volume and connect Pi to power and to the network via a usb ethernet adapter

Setting up Pi

  1. Remove heat sink paper layer blocking adhesive and install on CPU
  2. Insert SD card into Pi
  3. Connect Pi to micro usb power input
  4. Connect Usb ethernet adapter to Pi and router
  5. Find the Pi’s ip address on your router wired connection list or via thenmap command

6. Ssh into Pi using the ipaddress: ssh pi@192.168.29.220
7. password = raspberry

8. Are you sure you want to continue connecting (yes/no/)? yes

Set a static ip address for your wired in Pi

  1. sudo nano/etc/dhcpcd.conf
  2. Set the static ip_address to match your current ip address with a /24 at the end
  3. Set the static routers and static domain_name_servers to match the ip address of your router

4. Hit Ctrl-Xto exit the file and then press the letter “y” and hitenterto save changes

5. Reboot the Pi by typing sudo reboot

6. Confirm the ip address on your Pi by running ifconfig

Pi ip address

Update Pi password

  1. Run this on the terminal: passwd
  2. Type current password: raspberry (Note: Input does not move when typing)
  3. Enter new password, and then confirm it again
Changing Pi password

Install pi-hole

curl -sSL https://install.pi-hole.net | bash
  1. Hit yes/continue on the installation wizard until you reach “Choose and Interface”
  2. Select eth0 since we are wired in
  3. Select Upstream DNS Provider = Google
  4. Pi-hole relies on third party lists in order to block ads; Select Tab + Enter
  5. Do you want to use your current network settings as a static address? Select “yes”
  6. Do you wish to install the web admin interface?; Select Tab + Enter
  7. Do you wish to install the web server (lighttpd) and required PHP modules?; Select Tab + Enter
  8. Do you want to log queries? ; Select Tab + Enter
  9. Select a privacy mode for FTL. ; Select Tab + Enter
  10. Configure your devices to use pi hole as your DNS server; Hit enter
  11. You should be back on the terminal now and should see an Installation Complete message along with a password
  12. Change the password by running pihole -a -p
  13. Enter new password; hit enter; confirm password; hit enter

Change router DNS to point to pihole ip address

  1. Once that is done you should start seeing queries hitting your pi-hole admin
  2. Start playing around with the admin by visiting the ip address of your pihole: http://192.168.29.220/admin/index.php
  3. Hit the login button and start analyzing all the traffic

4. Go to the query log and see what traffic is getting allowed/blocked

Query Log Link

5. Analyze the traffic by client and whitelist or blacklist the URL if needed

Query Log Traffic

For more information on how to allow(whitelist) or block(blacklist) urls please visit the following.

Enjoy your private no ad browsing at home for all the devices on your network!

Thank you Gian for the idea, inspiration and support. Visit https://faq.giyo.us/ for more cool ideas and projects :)

--

--