Most orders for IN STOCK items placed by 12PM CST M-F ship SAME DAY. Orders for custom items and prints may take additional time to process.

How to Setup a Raspberry Pi Ad Blocker

Ads: who needs ’em? Well, this website needs them to keep the lights on. But you don’t need them, right? That’s why ad blockers, usually in the form of browser extensions, are so popular. The problem with browser extensions, though, is that they only work with certain browsers or on certain devices. What if you wanted to block ads from your desktop, laptop, smartphone, and tablet simultaneously? And what if you could do that in one fell swoop using a simple Raspberry Pi ad blocker?

I’ve got some good news for you! As you might have guessed, all of this is possible, and your step-by-step guide to making your own Raspberry Pi ad blocker is just a few flicks of the scroll wheel away.

How your Raspberry Pi ad blocker will work

Before we get into the nitty-gritty, though, let’s do a quick overview. This is not a particularly tough project, and that’s all thanks to the software that it uses: Pi-hole. Pi-hole bills itself as a “black hole” for ads, and it works by running an ad blocker in a DNS service (DNS stands for domain name system, but knowing that isn’t too important to this project). All we have to do is install Pi-hole on a Raspberry Pi that is already running a supported operating system and then change our router settings to ensure that all of our internet traffic is going through the DNS server that Pi-hole is using. Ready? Let’s get started.

Parts List for Pi-Hole

If you don’t already have everything you need, here’s a quick parts list for this project:


We’ll be installing Pi-hole in Step 1, but in order to do that we’ll need to have a Raspberry Pi with a supported operating system installed. By far the most popular of the operating systems that Pi-hole works with is Raspbian (you can see the other options on Pi-hole’s website), but there’s a catch: as of this writing, Pi-hole works with Raspbian Jessie and Raspbian Stretch, but not the most recent version, Raspbian Buster.

And that’s a tricky thing, because these older version of Raspbian won’t work on the newest Raspberry Pi hardware, the Raspberry Pi 4. This means that you can currently only do this project with an older Raspberry Pi and with Raspbian Jessie or Stretch. I used a Raspberry Pi 3B and Raspbian Stretch, which you can download here.

This isn’t totally surprising, as the Raspberry Pi 4 and Raspbian Buster both just came out this summer. Pi-hole will most likely add support for Raspbian Buster soon, and there’s no reason to assume that the installation process will look any different at that point than it does right now.

Step 1: Install Pi-hole

There are a few different ways that you can go about installing Pi-hole, but by far the easiest is to fire up your Raspberry Pi, pop a Terminal window open, and type this command:

curl -sSL https://install.Pi-hole.net | bash

That will get you started, but you’ll have some questions to answer and settings to confirm before the process is complete.

Installing Pi-Hole

Step 2: Keep right on installing Pi-hole (by confirming a few questions)

The command you just entered should kick things off with Pi-hole’s installation wizard. Now it’s time to okay a few settings for your new server program. There’s a lot to consider, but the good news is that casual Raspberry Pi enthusiasts can hardly go wrong by just opting for the default options each time. Here’s a quick run-through of what you’ll see:

After introducing itself and explaining that Pi-hole needs a static IP address, Pi-hole may ask you to choose an interface. Choose Eth0.

Pi-hole will ask you to select a DNS provider. Google is the default choice, but feel free to pick whichever one you’d like.

Next, you can select if you want to block ads over IPv4, IPv6, or both. If you hate ads no matter what, you can just keep both.

installing pi-hole

The most important question Pi-hole asks is the next one: What IP address should it use? If you want to ensure that you don’t give Pi-hole an IP address that your router might later assign to one of your connected devices, you can tell Pi-hole that, <no>, you don’t want to use your current network settings, and then input an IP that is outside of the range that your DHCP service (which assigns IP addresses to the devices on your network) would use. But a decent router will probably not make this mistake, and you can always go back and fix things if you hit <yes> and it doesn’t work out.

Pi-hole next asks to install the web admin interface, which you should probably agree to do.

Next is the web server, which you should agree to install.

Then there’s query logs, which Pi-hole recommends you leave on.

Next is a privacy setting, which is up to you.

installing pi-hole

When you’ve answered everything, Pi-hole will install. When it’s all done, you’ll be greeted with a confirmation screen. Don’t hit okay just yet, though!

Step 3: Record that IP address!

With the installation complete, you now have a Raspberry Pi running an ad blocker on a DNS server. But you don’t yet have a network-wide Raspberry Pi ad blocker, because your internet traffic isn’t going through that DNS server. In the next step, we’re going to make that happen — but in order to tell our router to use the proper DNS server, we first need to know what the IP address of that server is. No problem: it’s right here on this confirmation screen.

installing pi-hole

I have tastefully blurred out the IP on my own screen, but you can see where it is. Take note of the web interface address and admin login password, too. Jot everything down or take a photo of this screen before moving on.

Step 4: Route your traffic through the right DNS server

There are actually two ways to get all of your internet traffic running through the ad-blocking DNS server. One option is to let Pi-hole take over DHCP, which is the protocol used to assign IP addresses within your network, from your router. But the simpler option is to just change the IP address of the DNS server in your router’s settings to match the one you chose with Pi-hole earlier on. That’s the method I’ll use below.

The first thing you’ll need to do here is log into your router. To do this, just hop into a browser and enter your browser’s IP address in the address bar (it’s usually, but not always, going to be — check for stickers on your router or Google your router’s manufacturer for more information).

You’ll have to use your intuition a bit here, since not every router’s admin interface is set up the same way. What you need to do is find the settings for your DNS server and change both the primary and secondary DNS server IP addresses to your Pi-hole IP address — the one that you jotted down back in Step 3.

Save the new setting, and then reboot your connected devices. Your internet traffic should now be routed through Pi-hole, effectively eliminating ads all across your home network!

RELATED: More Great Raspberry Pi Projects!

Other important stuff

You can more or less forget about your ad blocker now, if you so desire. But it’s worth covering a couple of other things here.

The web admin interface

Pi-hole doesn’t require its users to hop back on their Raspberry Pi in order to change settings on their ad blocker. To check in on your Raspberry Pi ad blocker, you just need to head to http://pi.hole/admin (or to the other url you saw in Step 3).

Log in with your URL, and you’ll find records of the queries your DNS server has been handling. You can check out the query log and fine-tune your ad blocker by blacklisting sites — or whitelisting them, which we’ll talk a bit more about in a second.

Whitelisting sites

By default, your Pi-hole Raspberry Pi ad blocker will block anything and everything that it finds on its lists of ads. But it is possible to let some ads through the filters. This is a great way to help support sites that you like, because most websites (especially free ones) rely on ad revenue to stay afloat. If you’re feeling benevolent, here’s how to let a site show ads to you.

whitelisting sites

Start by logging into the web admin interface as explained above. Then, click “Whitelist” on the left-hand navigation menu. To whitelist a domain, just enter it into the text box and hit “add.” Make sure you’re using the top-level domain if you want to whitelist the whole site.

Upgrade to Premium

If you like our content maybe consider upgrading to Premium. You’ll get access to

  • Free access to all plans
  • Member only videos
  • Early access to content
  • Ad free Experience
  • Discounts on store merch
  • Direct hotline contact form

7 Responses

  1. I love Pi-hole and how it filters anything I add to the blacklist as well. I have YouTube blacklisted, but want to allow certain videos for K-12 education purposes on my kids’ iPads. Is that possible? All YouTube except a few select ones blocked?

Leave a Reply