Pi-hole is free and open source software for setting up a DNS (Domain Name Service) and DHCP (Dynamic Host Configuration Protocol) server with built-in functionality to be able to block ads, trackers, and other websites. As a DNS server, it is setup to block unwanted / undesired traffic on your entire network without needing to install anything on your smartphone, laptop, or other devices. You simply setup the Pi-hole, configure your network, and everything just works for all devices connected to the network.

Most often Pi-hole is talked about as being used for blocking website advertisements on a home network. This is just one very specific use case. Pi-hole can be used on any network, so long as the hardware it’s installed on has the resources to handle all the DNS queries of that network. As such, you can also install Pi-hole on a small business network to block undesired websites, and this is a really great cheap option for businesses.

Pi-hole works on the DNS (Domain Name Service) level. DNS is what your compute uses to turn a domain name (such as build5nines.com) that is typed into a web browser, into the IP Address (such as 8.8.8.8) that the computer connects to in order to download and display the requested web page. This DNS Lookup is performed not just within the web browser, but by any software that is requesting to communicate with a server on the Internet; such as any apps on your smartphone, computer, tablet, or other devices. By setting up Pi-hole as the DNS server on your network, it intercepts all DNS name resolution requests, and enables you to block those that you don’t want; such as ads, trackers, or even any NSFW websites.

Now, let’s dig into setting up Pi-hole on a Raspberry Pi!

Prerequisites

Pi-hole is server software that runs on LInux. You will need a computer that runs linux to install it, and that can be a Raspberry Pi (as this article discusses) or Pi-hole can even be run in a Container to integrate it within any network.

Since we are looking at setting up a Raspberry Pi to run Pi-hole, you will need the following items:

  • 1x Raspberry Pi – A Raspberry PI 2, 3, or 4 will work, as will a Raspberry Pi Zero*
  • 1x microSD Card (4 GB or larger) – This provides the storage to install the Raspbian Linux operating system on the Raspberry Pi.
  • 1x Micro-USB Power Cable or Supply – This will be used to power the Raspberry Pi.
  • 1x Ethernet cable – This is used to connect the Raspberry Pi to your network router.
  • 1x Raspberry Pi case (Recommended) – There are a number of cases for the Raspberry Pi; while not required it is recommended.

*If you choose a Raspberry Pi Zero, then you will need an adapter for connecting an Ethernet cable, as this version does not have an integrated Ethernet port. The Raspberry Pi 2, 3, and 4 all have integrated Ethernet ports onboard.

Here are some links where you can buy the items needed to setup your own Raspberry Pi Pi-hole:

Before Pi-hole can be installed on a Raspberry Pi, you will need to install Raspbian Linux on the microSD card. When installing Raspbian on the Raspberry Pi, I personally recommend using the Raspbian Buster Lite image and configure the Raspberry Pi to be headless (aka not need any display or keyboard). You can create a file named ssh on the SD card after flashing the image, then when the Raspberry Pi is plugged into Ethernet and powered on, you can use SSH to connect to it over your network. Just look up the IP address it’s assigned from your router and use the username / password of pi / raspberry to login to it.

Install Pi-hole

Once the Raspberry Pi is powered on you will need to install Pi-hole. This can be done by connecting it to a display & keyboard, or doing it headless by connecting to it over SSH. I recommend the headless setup (as mentioned above) as that will enable you to easily manage the Raspberry Pi device later on from anywhere on your network as needed.

To install Pi-hole on the Raspberry Pi, once booted up into Raspbian Linux, run the following command to perform the automated install:

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

Once the script is downloaded and begins executing, follow the guides steps to setup the Pi-hole configuration. If you are unfamiliar with the settings to choose, then just go with the default values to get up and running. Everything can be changed later anyway if necessary.

Setup Pi-hole as your DNS Server

Once Pi-hole is installed on the Raspberry Pi, you will want to go into your router configuration and perform the following 2 actions:

  1. Set the Pi-hole Raspberry Pi device to be assigned a Static IP Address. This will ensure the Raspberry Pi is assigned the exact same IP Address on your network every time it boots up.
  2. Configure the Custom DNS Settings in your router configurations to use the Pi-hole’s IP Address. This will enable your network to use the Pi-hole DNS server instead of your ISPs.
Block Ads, Trackers, and NSFW Sites on Your Network using Pi-hole and Raspberry Pi 1
Screenshot: Custom Primary DNS Address in router set to use Pi-hole

After Pi-hole has been installed, a static IP Address is assigned, and the Custom DNS Server settings are configured on your router, the Pi-hole will begin to block ads, trackers, and other unwanted traffic it’s configured to with the blocklist and whitelist features set.

Remotely Accessing and Managing Pi-hole

Once the Pi-hole is setup on your network, you can easily use a web interface to manage the Pi-hole configurations, as well as view the status of the DNS queries it’s been allowing and those it’s blocked. This is provided for you with a nice web based dashboard that can be accessed at the IP Address of the Pi-hole like this: http://<ip-address>/admin

When you first configured the Pi-hole it will have given you a password that you can use to login to the Pi-hole Dashboard web app.

Block Ads, Trackers, and NSFW Sites on Your Network using Pi-hole and Raspberry Pi 2
Screenshot: Pi-hole Dashboard in Action

Setup Whitelist and Blocklist of Sites / DNS Names

When the Pi-hole is setup, it will be pre-configured with some Blocklists that block certain websites. This will be setup for you if you choose the default values during the installation. If you find any sites are being blocked that you don’t want to be, then you can use the whitelist feature to explicitly allow those particular domains. Also, if you specifically know certain sites you want blocked, you can use the blocklist to do that as well.

The default blocklists setup include a few that will generally block DNS requests for domains that host Ad platforms and online Trackers. Blocking ads is the most noted use of Pi-hole. However, you can use this to import any Blocklist you want, including one you create yourself, or even those created by the community.

For example, one that I found useful from the community is a blocklist hosted on GitHub and managed by Chad Mayfield that contains a massive list of adult or pornographic website domains. Using the Pi-hole and Chad’s blocklist, I am able to block MANY of the pornographic websites on the Internet that I especially do not want my young kids to be accessing by clicking some random link or advertisement on the web. Also, if you set this up for a small business you can help ensure you get the same protections there too!

To add Chad Mayfields porn blocklist to your Pi-hole, go into the Settings -> Blocklists interface within the Pi-hole dashboard, and add the following URL:

https://raw.githubusercontent.com/chadmayfield/my-pihole-blocklists/master/lists/pi_blocklist_porn_all.list
Block Ads, Trackers, and NSFW Sites on Your Network using Pi-hole and Raspberry Pi 3
Screenshot: Pi-hole dashboard Blocklist configuration screen

Block Social Media and Messaging Services

You can use the blocklists feature of Pi Hole to create lists of all kinds of different sites and services you wish to block. You can even pull in blocklists that others have created to enhance your network protection and site / service blocking capabilities. Included in this mix, is the ability easily block certain social media services; like blocking TikTok.

I have put together a few blocklists that can be used to block social media and messaging apps (like Facebook, Twitter, Tumblr, Snapchat, and others). These block lists are hosted over on GitHub at https://github.com/crpietschmann/pi-hole-blocklist You can use these lists to help block the use of these social media and messaging apps / services. There is an individual blocklist available in the project for each service, including a set of combined all.txt blocklist files that combine multiple of the lists together to make it easier to pull them all in to your Pi Hole setup.

Here are a few of the specific block lists I have included in this project for some specific social media and messaging services:

TikTok blocklist

https://raw.githubusercontent.com/crpietschmann/pi-hole-blocklist/main/social-media/blocklist-social-tiktok.txt

Facebook blocklist

https://raw.githubusercontent.com/crpietschmann/pi-hole-blocklist/main/social-media/blocklist-social-facebook.txt

Snapchat blocklist

https://raw.githubusercontent.com/crpietschmann/pi-hole-blocklist/main/social-media/blocklist-social-snapchat.txt

Instagram blocklist

https://raw.githubusercontent.com/crpietschmann/pi-hole-blocklist/main/social-media/blocklist-social-instagram.txt

Twitter blocklist

https://raw.githubusercontent.com/crpietschmann/pi-hole-blocklist/main/social-media/blocklist-social-twitter.txt

Whatsapp blocklist

https://raw.githubusercontent.com/crpietschmann/pi-hole-blocklist/main/messaging/blocklist-messaging-whatsapp.txt

The above is not a full list of social media and messaging service blocklists added to the project. For the full list, please go visit the crpietschmann/pi-hole-blocklist project directly. Also, I will try to add to these blocklist files in traditional open source fashion, so please feel free to submit a pull request to help ad to them.

Update Pi-hole

Over time, there will be updates and fixes released for the Pi-hole software. It’s important with Pi-hole, as with all software, that you periodically install all updates. By installing updates this will ensure you get bug fixes, and any fixes for security vulnerabilities to keep you Pi-hole secure and up-to-date. Additionally, when new features are added over time to the Pi-hole software, updating will ensure you get access to those as well.

To update the Pi-hole, simply connect to the Pi-hole server over SSH, then run the following command:

pihole -up
Block Ads, Trackers, and NSFW Sites on Your Network using Pi-hole and Raspberry Pi 4
Screenshot: Updating Pi-hole to latest available version

Also, if you wish to check for available updates, but want to review them before applying them, then run the following command which will simply output the available updates for you and then exit before applying them:

pihole -up --check-only
Block Ads, Trackers, and NSFW Sites on Your Network using Pi-hole and Raspberry Pi 5
Screenshot: Check for available updates to Pi-hole without applying them

Wrap Up

Pi-hole is great ad helping block ads, as the main reason most people use it. However, it can also be used to block any other websites desired, such as those that are NSFW (not safe for work) or even NSFF (not safe for family) too. Also, as a DNS server on your network with the web based dashboard interface, it provides additional capabilities to be able to have some insights into what sites and domains are being accessed from devices on your network. You can use this to help keep your devices, your network, and your business or family safe and secure online.

Happy home (or small business) networking!

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
Microsoft MVP HashiCorp Ambassador

Discover more from Build5Nines

Subscribe now to keep reading and get access to the full archive.

Continue reading