How To Block Ads On Your Network Using Pi-Hole And A Raspberry Pi

Blocking ads on your local network is really straightforward with a raspberry pi all you need to do is install some software called Pi-Hole on it and then make sure you use the Raspberry Pi as your DNS server instead of Google ( or Cloudflare ( directly. You can still use those, but they will be the upstream of your Pi-hole instance instead. Later on you can dive into this article where I actually integrate a DNS Proxy service called SmartDNS into Pi-Hole which enables me to block ads and get BBC iPlayer outside of the United Kingdom and the full US Netflix catalog.

What you will need: (a router, computer and internet goes without saying…)

  • A Lan cable to connect the Raspberry Pi to your router on your home network.
  • A USB memory card reader to load the OS onto the SD card.
  • A Raspberry PI computer and a memory / SD card (I recommend a SD card with 16GB minimum, but you can get away with 8GB), you will need the Pi 3 Model B or Model B+ you do not need a Pi 4, but if you want one it will work better as it is a lot more powerfull, but the Pi 3 is more than sufficient for what we are going to use it for.

You can buy a Raspberry Pi from these places depending on where you live:

If you live in the United States or in the United Kingdom:

Raspberry Pi Kit (includes a case, a memory card, power adaptor and the PI itself) from Amazon this is the one I used in the tutorial, very neat set up.

If you live in South Africa:

Raspberry Pi Kit from PiShopNetram or DIY Electronics. I have used all of them before.

Note: Shop around on classified sites as well for a second hand raspberry pi, you will see people buy this computer thinking it will change their lives and then not realize its just a normal small form factor PC, it cannot do anything without you programming it to do something and then people end up selling it at half price. In other words, check gumtree, check craig’s list and Ebay, there are bound to be a lot of specials on second hand Raspberry Pi computers.

Step 1: Install an operating system on your Raspberry Pi

We will be installing the Raspberry Pi OS (previously called Raspbian) as this is the primary operating system which the Pi Hole Devs test their system against followed by Ubuntu and Debian.

On a high level, this is what we will do: We are going to download the operating system and we are going to download a program that can write that OS to the physical memory card using your USB memory card reader. Once that is done you will put the memory card into the Raspberry PI and connect to it via a LAN cable from your PC (this is a headless installation – meaning you won’t plug a keyboard or monitor into the raspberry at all.) and then run the setup scripts to install Pi Hole which we will then control via the browser.

Let us get started

We are specifically going to use “Raspberry Pi OS (32-bit) Lite”, which you can download from here. After you downloaded this, please download the software required to write it to the SD card, called Raspberry Pi Imager from here.

Connect an SD card reader with the SD card inside.

Open Raspberry Pi Imager and choose the required OS (Raspberry Pi OS lite, 32 Bit) from the list presented.

Install the raspberry pi imager program to install raspberry pi os

Choose the SD card you inserted into your computer via the USB card reader in order to write the image to it.

Review your selections and click ‘WRITE’ to begin writing the data to the SD card.

Note: if you are using the Raspberry Pi Imager on Windows 10 with “Controlled Folder Access” enabled, you will need to explicitly allow the Raspberry Pi Imager permission to write the SD card. If this is not done, Raspberry Pi Imager will fail with a “failed to write” error.

Now you need to create a file called “ssh” without and extension and place it inside the boot partition. If you go to “This PC” on your windows machine and look at the SD card you will have two partitions. The first one, which is the smaller one, is the boot partition. Place the file into this one.

We do this because when the Pi boots, it looks for the ssh file. If it is found, SSH is enabled and the file is deleted. The content of the file does not matter; it could contain text, or nothing at all.

You can now insert the SD card into the Raspberry Pi and power it up.

how to insert an sd card into a raspberry pi
Step 2: Connect the Raspberry Pi to your Router

Plug the lan cable into your raspberry and plug the other part into your router.

Step 3: Find the IP Address of the Raspberry PI

In a web browser navigate to your router’s IP address e.g., which is usually printed on a label on your router; this will take you to a control panel. Then log in using your credentials, which is usually also printed on the router or sent to you in the accompanying paperwork. Browse to the list of connected devices or similar (all routers are different), and you should see some devices you recognise. Some devices are detected as PCs, tablets, phones, printers, etc. so you should recognise some and rule them out to figure out which is your Raspberry Pi. Also note the connection type; if your Pi is connected with a wire there should be fewer devices to choose from.

If you struggle with this step, follow me on Twitter (@ErikThiart) and send me a tweet with a picture of your router then I will explain how to do it for your particular router.

Alternatively, you can get the IP address of a Pi using your smartphone by downloading the Fing App. Your phone and your Raspberry Pi have to be on the same network, so connect your phone to the correct wireless network.

When you open the Fing app, touch the refresh button in the upper right-hand corner of the screen. After a few seconds you will get a list with all the devices connected to your network. Scroll down to the entry with the manufacturer “Raspberry Pi”. You will see the IP address in the bottom left-hand corner, and the MAC address in the bottom right-hand corner of the entry.

Step 4: SSH into your Raspberry Pi using Putty (on windows).

Download & Install Putty. It is not really an Install as you can run the putty.exe directly.

Open Putty

how to enter an ip address into putty in order to use ssh

Enter the Raspberry Pi IP address, select SSH as connection type and under the menu item “Window” –> “Translation” select UTF-8

Click “Open” and you’re ready to log on.

Next you will be prompted for the password for the user as which you are trying to connect: the default password for the pi user on Raspberry Pi OS is raspberry. For security reasons it is highly recommended to change the default password on the Raspberry Pi.

You will see the following:

pi@raspberrypi ~ $
Configuring putty to use UTF-8 during ssh to the raspberry pi

You are now connected to the Raspberry Pi remotely, and can execute commands.

Step 5: Install Pi-hole on the Raspberry Pi

This bit is the easy part. Their intelligent, automated installer asks you a few questions and then sets everything up for you automagically.

Type in the following command into the putty terminal after you logged into the raspberry pi and press enter:

curl -sSL | bash
Install Pi-Hole on a raspberry pi using ssh

Follow the steps that will come up on the screen, they are mostly very easy to understand, send me a tweet if you get stuck.

Step 6: Use Pi-hole as your DNS server

Configure your router’s DHCP options to force clients to use Pi-hole as their DNS server, or manually configure each device to use the Pi-hole as their DNS server.

Log into your router’s configuration page and find the DHCP/DNS settings. Note: make sure you adjust this setting under your LAN settings and not the WAN.

Update the DNS setting on a router for Pi Hole

Important: If you have existing network devices on your network when you make this change, you will not see ads getting blocked until the DHCP lease is renewed. You can usually force a renewal by restarting the device.

Again, if you need help during this step, tweet a picture of your router to me on @ErikThiart and I will guide you through the process for your particular router.

Step 7: Get to know Pi Hole & accessing the Ad Blocker GUI via the browser.

You can access it by typing the IP address of your Raspberry Pi into your browser. In addition to blocking advertisements, Pi-hole has an informative Web interface that shows stats on all the domains being queried on your network. They also include an API for extending these stats.

Access the Pi Hole GUI through a browser

Queries are stored in a database and can be queried at any time. It allows you to learn about what’s happening on your network over time for example if you have an Amazon Alexa or Google Home Mini you can check if they are listening to you by eavesdropping into your private conversations.

Bonus: Additional Documentation for Pi-Hole

You can visit the official Pi Hole website if you get stuck along the way, or you can send me a tweet via Twitter (If you follow me then I respond near instantly).

If you found this guide to be useful and would like to make a donation, please head over to my donations page, I appreciate all the support I have received over the years from various readers around the world.

Popular Categories

Ad Blockers AWS Bitcoin CMD cPanel crypto Dark web Google IoT MikroTik Python Reviews SmartDNS Sonoff Tor VPN Windows WordPress Xiaomi Youtube Raspberry Pi

Subscribe (It's Free)

Featured Articles

A smart bulb that works with the eWelink app
A smart bulb that works with the eWelink app

The Sonoff lightbulbs are very affordable and provide you with the basic functionality that a smart home needs. If the budget is tight and you don’t need all bells and whistles of the more expensive lights, Sonoff lightbulbs will do the job just fine. The prices start from $9.90 for the (plastic, White + color temperature) B02 B A60 and $12.90 for the fancy, pear-shaped B02-F-ST64 (glass, retro look, White + color temperature). As far as connected lights go, the prices are very attractive and Sonoff lightbulbs indeed are as inexpensive as you can get.

Read The Article
How to buy bitcoin on Binance?
How to buy bitcoin on Binance?

Binance exploded onto the scene in the mania of 2017 and has since gone on to become the top crypto exchange in the world. The company is very dedicated to making the exchange the premier source for trading, there are many trading events all the time, and coin approval doesn’t come without solid review. This allows for an exchange where every coin on it is considered to some degree legitimate. Binance actually understands the mindset and ethos of the crypto-community and the mantra of decentralization, it’s no wonder that they have the highest trading volume in the world while being a relatively new exchange.

Read The Article
The tools, habits, and hardware needed to speed up your computer
The tools, habits, and hardware needed to speed up your computer

Whether it happens gradually over time or all of a sudden, trying to work with a slow computer can be seriously frustrating. Even if you’re fairly diligent with the maintenance of your laptop or PC, it’s surprising how quickly things slow down. If you are asking yourself “Why is my laptop so slow” and running Windows 10, 8, or 7, this post is for you!

Read The Article

Some articles you might also be interested in...

How to block ads on your network using Pi-Hole and a Raspberry Pi
How to block ads on your network using Pi-Hole and a Raspberry Pi

With Pi-Hole you can block in-app advertisements. Network-level blocking allows you to block ads in non-traditional places such as mobile apps and smart TVs, regardless of your hardware or OS and since advertisements are blocked before they are downloaded, network performance is improved and will feel faster. Pi-hole is a black hole for Internet advertisements.

Read The Article
Xiaomi Mijia 1080P 170 Degree Smart IP Camera with AI Human Detection
Xiaomi Mijia 1080P 170 Degree Smart IP Camera with AI Human Detection

I know this review is long, but I wanted to include all the details to help you decide. This smart security camera from Xiaomi had so much going for it, I still believe there a route for Xiaomi to redeem themselves and make this camera available to its full potential by issuing a firmware update to remove the restrictions and allow RTSP access from the Xiaomi camera.

Read The Article
Force all DNS traffic to go through Pi-hole using Mikrotik
Force all DNS traffic to go through Pi-hole using Mikrotik

The following mikrotik firewall rules will force all the clients on your local network like your Sony PlayStation and Google Chromecast to use your Pi-hole or your own local server as their primary DNS server, even if they have hard coded their own DNS servers we do this because many apps and devices do not use the offered DNS servers per DHCP, they are just that – an offer. Hardcoded DNS servers will still resolve and allow ads and tracking unless we use NAT rules that will redirect all DNS requests, no matter where they go, to the Pihole.

Read The Article