How to Block Ads Network-Wide With Pi-hole on Raspberry Pi
Using Pi-hole, your Raspberry Pi can filter ads before they reach your devices.
While online advertising is a major revenue source that allows your favorite websites, including this one, to make money, sometimes people want to block it for various reasons such as performance or privacy concerns. You could install blocking software on each device you own, but the most efficient way is to create a server using Pi-hole that filters all your web traffic at the local network level.
Pi-hole is a Raspberry Pi based network wide ad blocker. We install the software to a Raspberry Pi running Raspberry Pi OS, run a short installation script and then point our machines to the Raspberry Pi’s IP address for instant ad blocking. We can also -- and we strongly encourage this -- add the sites you use frequently like tomshardware.com to a whitelist so you can help them keep the lights on.
In this tutorial we will turn a spare Raspberry Pi into an ad blocking machine, tucked safely away on our network. We used a Raspberry Pi 4, but given the low requirements for Pi-hole, this is an excellent chance to resurrect that old Raspberry Pi that you have lurking in a drawer.
For This Project You Will Need
- Any Raspberry Pi with Ethernet
- Power and Ethernet cable for your Raspberry Pi
- A Windows PC
Setting Up Your Raspberry Pi
1. Download and install Raspberry Pi Imager from the Raspberry Pi website.
2. Insert a spare microSD card into your computer. Note that this card will be erased.
3. Launch Raspberry Pi Imager and press SHIFT + CTRL + X to open a secret configuration menu.
4. Scroll down and click on Enable SSH and then set a new SSH password. Click Save when done.
Stay On the Cutting Edge: Get the Tom's Hardware Newsletter
Get Tom's Hardware's best news and in-depth reviews, straight to your inbox.
5. Under Operating System select Raspberry Pi OS (32-bit).
6. Under Storage click on the button and select the microSD card. Double check that you have the right drive before proceeding.
7. Click on Write to download and write Raspberry Pi OS to the microSD card. When done remove the card from your computer.
8. Insert the Raspberry Pi OS microSD card into your Raspberry Pi. Then connect your Raspberry Pi to the network via an Ethernet cable and finally connect power to boot the Raspberry Pi.
Installing Pi-hole Over SSH
SSH, a secure connection to your Raspberry Pi, is the best way to install and setup Pi-hole. We can use an SSH client to connect. For Windows this is PuTTY, and Mac, Linux users can directly connect via the terminal. With SSH we can install software and administrate the Raspberry Pi as if we were sitting in front of it.
1. Windows users, download and install PuTTY. Linux and Mac users can directly open a terminal.
2. Via PuTTY enter the hostname as raspberrypi.local (on some networks, this is just raspberrypi without the .local) and then click Open.
3. Enter your username and password when prompted. Note that these are not printed to the screen for security purposes.
4. Update your software repositories and then download the latest updates for your Raspberry Pi.
$ sudo apt update
$ sudo apt upgrade -y
5. Install Pi-hole using this one line installation script. This command will download the script and then run the installer in the terminal.
$ curl -sSL https://install.pi-hole.net | bash
6. The Pi-hole installer will start by updating the available software, and then a menu based installation wizard will start. Press Enter to progress through the installation.
7. Choose eth0 as the interface to use with Pi-hole. Press Tab to move the red highlight to Ok and then press Enter. This is our Gigabit Ethernet port which will provide the best possible connection.
8. Select your upstream DNS provider. We chose Google, but there are many others to choose from. Press Tab and then Enter.
9. Accept the default list of blocked sites by pressing tab and enter.
10. Accept the default IPv4 and IPv6 protocols by pressing tab and enter.
11. Accept the current network settings, and set them as static. Do make a note of the details as we will need them later.
12. Install the web admin interface by pressing tab and enter.
13. Install the lightppd web server used to serve the web admin pages by pressing tab and enter.
14. Accept the default log options.
15. Accept the default privacy mode by pressing tab and enter.
The installation is complete and the final page recaps the IP address of the Pi-hole device and provides an admin webpage login password.
16. Change the web admin password in the terminal using the following command. You will be prompted to type in the password twice.
$ pihole -a -p
Setting Network Connections for Pi-hole
With our Raspberry Pi running Pi-hole setup and running we now need to point our devices to it so that Pi-hole’s DNS servers can block unwanted advertisements. Here we are manually setting up a wired network connection with Windows 10. The steps will be similar for Wi-Fi.
1. Right click on the Windows logo and select Network Connections.
2. Click on Properties.
3. Click on Edit to update the network configuration.
4. Edit your IP address to your desired address. We chose to stick with what the router’s DHCP server issued. Set the Subnet prefix length to 24. The Gateway is the IP address of the router, in our case 192.168.0.1. Preferred DNS is our Pi-hole DNS server, 192.168.0.24. The Alternative DNS is used if our Pi-hole device goes offline, in this case it is Google’s DNS server. Click Save to write the changes and restart the network interface.
How to Whitelist a Site in Pi-Hole
Considering that many content sites, including ours, rely on advertising for a significant portion of their revenue, it makes sense to whitelist those you wish to support so they can serve you ads. Pi-hole has a whitelist menu where we can add specific domains and subdomains which will be added to Pi-hole’s lists.
1. Open a web browser to the IP address of your Raspberry Pi, and type /admin. For our setup we went to http://192.168.0.34/admin/
2. Log in to your Pi-Hole by entering the username and password. We earlier changed the admin login password.
3. From the dashboard click Whitelist.
4. Under Domain, add the URL of the site that you wish to whitelist, then click Add to Whitelist. This site will now be able to serve adverts.
Domains can be enabled / disabled in the whitelist by clicking on the button under Status. Whitelisted domains can be deleted by clicking on the trashcan icon.
5. Click logout to return to the default admin page.
There you have it, your browser tabs are free of adverts and your browsing just got a lot faster, all thanks to that spare Raspberry Pi that was lurking in your drawer.
Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".
-
burritokid Nice article. Been using a pi hole connected to my router for ages but wasn't aware of the whitelist domain option, so good catch! 👍Reply -
pixelpusher220
How often do you encounter sites that don't function due to the pi-hole?burritokid said:Nice article. Been using a pi hole connected to my router for ages but wasn't aware of the whitelist domain option, so good catch! 👍
I'd love to do it but with the non-techies in my household, the tech support job is mine...lol -
Buggedsee
I've been using pi-hole for about 2 years now and I've never encountered a site not working. The main issues is with my wife browsing Etsy and Instagram and not being able to go to the ad sites (she regularly tells me). Also, sponsored links in Google searches don't work, but that's it from our experience.pixelpusher220 said:How often do you encounter sites that don't function due to the pi-hole?
I'd love to do it but with the non-techies in my household, the tech support job is mine...lol -
Buggedsee Admin said:Using Pi-hole, your Raspberry Pi can filter ads before they reach your PCs, phones or tablets.
How to Blocks Ads Network-Wide With Pi-hole on Raspberry Pi : Read more
Small comment on your whitelisting... If your site serves the ads the whitelisting will work, but as the ads are NOT served by tomshardware.com whitelisting it does nothing... -
vishnumrao pixelpusher220 said:How often do you encounter sites that don't function due to the pi-hole?
I'd love to do it but with the non-techies in my household, the tech support job is mine...lol
Many times. As an example a redirect from deal websites like slickdeals will not work. I guess these redirects are tracked for hits and sale etc. My wife mostly browses on her phone. She deafeats or rather works around the pihole block by turning off wifi (much to my frustration, :) ) -
Kamikaze5110 Sadly i buyed Rpi zero for using pi-hole just for one reason... Youtube on Smart TV. But unfortunatly you can't block YouTube videos with Pi-hole. This should be mentioned in article.Reply -
pixelpusher220
This. I will happily allow ads directly from Toms or whatever site. It's the third party crap that's the problem. I have a very long whitelist built up in NoScript as I've tailored the minimum to get stuff working.Buggedsee said:Small comment on your whitelisting... If your site serves the ads the whitelisting will work, but as the ads are NOT served by tomshardware.com whitelisting it does nothing... -
mordsith I think this guide needs an update. I could not use the user "pi" anymore. Apparently, it is a security update in Rasp Pi OS? I searched long and hard and finally found a raspberry pi hole guide that addressed this point - for anyone facing any issues.Reply -
Viking2121 I've been running PiHole for quite a while, even blocks a ton of ads on the smart TV's, I run it on my media server and secondary on a PC thats on almost all the time.Reply
NextDNS is pretty good as well but its hosted off site, get 300K queries for free each month, 20 bucks for a year and bunch of block lists you can play around with. -
Bob0220
Can you be more specific as to where you found this guide?mordsith said:I think this guide needs an update. I could not use the user "pi" anymore. Apparently, it is a security update in Rasp Pi OS? I searched long and hard and finally found a raspberry pi hole guide that addressed this point - for anyone facing any issues.