How to Set Up Pi-hole on a Raspberry Pi
This article provides a step-by-step guide on how to transform a Raspberry Pi into a network-wide ad blocker using Pi-hole. By routing your network’s Domain Name System (DNS) traffic through the Raspberry Pi, you can block advertisements and tracking scripts on every device in your home—including smartphones, smart TVs, and computers—without installing individual browser extensions.
Prerequisites and Hardware Requirements
Before beginning the installation, you need to gather a few essential components. A standard setup requires a Raspberry Pi (almost any model will work, from the Pi Zero to the Pi 5), a microSD card (at least 8GB) with the Raspberry Pi OS installed, a reliable power supply, and an internet connection via Ethernet or Wi-Fi. It is highly recommended to use an Ethernet connection for lower latency, as this device will handle all DNS queries for your network. You will also need administrative access to your home router to change its DNS settings later in the process.
Step 1: Prepare and Update the Raspberry Pi
First, boot up your Raspberry Pi and open the terminal, or connect to it via SSH. It is crucial to ensure your system is completely up to date before installing new software. Run the following commands to update the package lists and upgrade all installed packages to their latest versions:
sudo apt update
sudo apt upgrade -yOnce the update process is complete, you should assign a static IP address to your Raspberry Pi. This step is vital because if your router reassigns a different IP address to the Pi later, your entire network will lose internet access. You can configure a static IP within the Raspberry Pi OS DHCP settings, or you can reserve an IP address for the Pi’s MAC address directly inside your router’s configuration dashboard.
Step 2: Install Pi-hole
The Pi-hole automated installer is streamlined and easy to use. To download and launch the installation script, execute the following command in your terminal:
curl -sSL https://install.pi-hole.net | bashThis command initiates an interactive installer that will guide you through the configuration. The installer will prompt you to confirm your static IP settings, select an upstream DNS provider (such as Cloudflare, Google, or OpenDNS) to resolve legitimate web addresses, and choose which default ad-blocking lists to activate. At the very end of the installation process, the terminal will display a unique administrator password and the web interface URL. Make sure to write this information down.
Step 3: Configure Your Router
With Pi-hole running on your Raspberry Pi, you must now instruct your router to use the Pi as its sole DNS server.
- Log into your router’s web admin portal using your web browser.
- Locate the DHCP or LAN settings section.
- Find the fields labeled Primary DNS and Secondary DNS.
- Input your Raspberry Pi’s static IP address into the Primary DNS field.
- Leave the Secondary DNS field blank or set it to
0.0.0.0to ensure devices do not bypass the Pi-hole.
Save the settings and restart your router, or disconnect and reconnect your devices to the network to force them to fetch the new DNS configuration.
Step 4: Access the Dashboard and Verify
You can now verify that the system is working by opening a web
browser on any device connected to the network and navigating to
http://pi.hole/admin or
http://<Your-Pi-IP-Address>/admin. Log in using the
admin password provided at the end of the installation script. The
Pi-hole dashboard offers real-time query logs, graphics showing the
percentage of blocked traffic, and tools to whitelist misunderstood
websites or blacklist additional ad domains manually.