How to block ads using a Raspberry Pi and the Pi-Hole software

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 (8.8.8.8) or Cloudflare (1.1.1.1) 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 PiShop, Netram 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. http://192.168.1.1, 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 https://install.pi-hole.net | 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.

Looking for something?

Article Categories

Some articles you might also be interested in...

How to access BBC iPlayer outside of the UK

You might have found that Hulu is limited to US viewers and the BBC iPlayer is likewise limited to UK IP addresses, however using a very easy to set up proxy server you can access BBC Iplayer, Hulu and many others from any country on all of your internet capable devices such as your Laptop, PC, Mobile Device, Kindle Fire TV, Apple TV, Google Chromecast etc. In this guide you get the ultimate viewing experience when streaming/downloading any type of regional or geo-blocked content online.

Read Article
How to download Youtube videos as MP3 files.

To convert a Youtube video or any video for that matter requires just one step, in essence you will transcode the video file (normally an MP4) to MP3 using ffmpeg. In this tutorial I will show you how you can convert videos to audio in a matter of seconds, it does not cost a cent and requires very little effort.

Read Article
How to monitor the power usage of devices using a Sonoff Pow R2

Sonoff Pow R2 is a 16A WiFi smart light switch that allows you to remotely manage and control your appliances and monitor your home energy usage. The WiFi light switch works like a power monitor, which allows you to keep track of 99% accurate real-time current, voltage and power on your app.

Read Article