Pi-Hole on Raspberry Pi: A Headless Guide for Network-Wide Ad Blocking
Welcome to this comprehensive guide on setting up Pi-Hole on a Raspberry Pi for network-wide ad blocking. This guide has been designed to provide you with a seamless, step-by-step process for configuring Pi-Hole without needing a monitor or wired keyboard.
Introduction
Pi-Hole is a powerful DNS sinkhole that protects your devices from unwanted content. In this guide, we'll show you how to configure Pi-Hole on a Raspberry Pi to block ads and improve network performance. The beauty of Pi-Hole is that it can be set up for individual device or network-wide ad blocking.
Requirements
Here's what you'll need for this setup:
- A Raspberry Pi with a power adapter
- An Ethernet cable
- An open Ethernet port on your router
At the time of writing, Raspberry Pi devices might be hard to come by or might be prohibitively expensive. An alternative is to use a Raspberry Pi Zero with an Ethernet to Micro USB Dongle, which may be considerably cheaper. You can track Raspberry Pi availability using https://rpilocator.com/.
Hopefully, the shortage will come to an end sooner than later.
Steps
Installing Raspberry Pi OS and connecting to the Pi
-
Install the Raspberry Pi Imager
You can install Raspberry Pi Imager on Mac using Homebrew with the command:
brew install raspberry-pi-imager
. Otherwise, you can download the software at: https://www.raspberrypi.com/software/ -
Format the Micro SD card using Raspberry Pi Imager
- Install and open Raspberry Pi Imager
- Under "Operating System", select "Erase" near the bottom
- Choose the storage location as the Micro SD Card
- Click "Write"
-
Install Raspberry Pi OS using Raspberry Pi Imager
- Under "Operating System", select "Raspberry Pi OS (other)"
- Then select "Raspberry Pi OS Lite (32-bit)". This is a good lightweight option if you're only using your Raspberry Pi for Pi-hole.
- Select the storage location as the Micro SD card
- Click on the advanced option gear on the bottom right
- Enable SSH - This is important to do via the installer otherwise you will need a keyboard and monitor to toggle on this function.
- Use password authentication and set your username and password.
- Skip configuring the wireless LAN as the Raspberry Pi will be connected via Ethernet.
- Set locale settings to match your current time zone.
- Click "Save", then "Write".
- Under "Operating System", select "Raspberry Pi OS (other)"
-
Insert the Micro SD card into your Raspberry Pi
After the Raspberry Pi OS has been written to the SD card, insert it into your Raspberry Pi. Connect the Ethernet cable and power up the device by connecting the power adapter. Give it about 5 minutes for the OS to install and configure.
-
SSH into the Pi
Using a terminal application, you can now SSH into the Raspberry Pi using the credentials you set up in the Raspberry Pi Imager's advanced options:
ssh username@raspberry.local
.
If needed, you can find the IP address of the Pi usingnmap
orarp
commands.Using nmap on Mac or Linux:
nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
Using arp:
Mac or Linux:$ arp -na | grep -i b8:27:eb
Windows:
arp -a | findstr b8-27-eb
Installing Pi-Hole
-
Update your Raspberry Pi
Before installing Pi-Hole, update your Raspberry Pi with the following commands:
sudo apt-get update && sudo apt-get upgrade
If asked to confirm, select "Y". This will take a few minutes to update and install packages.
-
Start Pi-Hole installation
Run the command
curl -sSL https://install.pi-hole.net | bash
.The Pi-Hole Automated Installer will appear after a few minutes. Continue with the prompts to set up a static IP address, select an upstream DNS provider (we recommend Cloudflare, then OpenDNS, then Google), and install with the Admin Web Interface and the web server enabled.
-
Configure Pi-Hole
During the installation, you can choose whether to include query logging and set your privacy mode. Once done, the installer will present you with your Pi-Hole DNS server details, including the web interface URL and your login password. Be sure to save these details.
Configuring Pi-Hole on Your Router
To ensure that all devices on your network benefit from the ad-blocking capabilities of Pi-Hole, it is recommended to configure your router to use Pi-Hole as its DNS server. Here's a general guide on how to do it:
-
Access Your Router's Admin Interface: This usually involves typing in your router's IP address into a web browser. The specific IP address and login credentials should be listed in your router's manual or printed on the back of the router itself.
-
Navigate to DNS Settings: Once you've logged into your router's admin interface, you need to find the DNS settings. The location of these settings varies greatly depending on your router's brand and model, but it's typically under a section labeled 'Internet', 'Network', or 'DHCP & DNS'.
-
Change DNS Server to Pi-Hole's IP Address: In the DNS settings, you should see your current DNS servers listed. You need to replace these with the static IP address of your Raspberry Pi (which is running Pi-Hole). This change will direct all DNS queries on your network to your Pi-Hole.
-
Save and Apply Changes: Once you've entered the Pi-Hole's IP address as the DNS server, save and apply the changes. You might need to reboot your router for the changes to take effect.
-
Check Pi-Hole's Admin Interface: After you've made the changes, you can check to see if it's working by going to Pi-Hole's admin interface. You should start seeing queries being processed and ads being blocked.
Remember, the steps may vary slightly depending on your specific router model. If you're unsure, consult the manual or the manufacturer's website.
The Pi-Hole post-install docs have much more detailed documentation on how to do this for each given router.
Now that your router is configured to use Pi-Hole as its DNS server, every device on your network that uses DHCP to obtain its IP address will also receive the Pi-Hole's IP address as the DNS server. This means all devices on your network will have ads blocked by Pi-Hole, without any additional configuration on the individual devices.
Open the Pi-Hole Admin Interface
If all is configured correctly, you may now login to Pi-Hole by navigating to:
Enhancing Your Pi-Hole
You can enhance the ad-blocking power of your Pi-Hole by adding more URLs to your blocklist. Simply navigate to "Adlists" in the Pi-Hole web interface and add a link to a new list. We recommend using The BlockList Project to find curated blocklists.
Conclusion
That's it! You've successfully set up a headless Raspberry Pi with Pi-Hole for network-wide ad blocking. Enjoy your ad-free browsing experience!
Leave a comment