Raspberry Pi Pi-hole Setup: Block Ads Network-Wide
In this article
Pi-hole is a network-wide ad blocker that runs on a Raspberry Pi. Instead of blocking ads on a single device, it acts as your entire network's DNS (Domain Name System) server. When a device on your network asks for a website address, Pi-hole checks it against a blocklist of known ad and tracker domains. If it matches, the request is dropped, and the ad never loads. This means ads are blocked on every device—phones, smart TVs, tablets, and computers—without installing any software on them. It also speeds up your browsing and reduces data usage. This guide walks you through the entire setup, from flashing the SD card to seeing your first blocked query in the dashboard. Before you begin, make sure you have a Raspberry Pi (any model from the 3B onwards works well), a microSD card (8GB or larger), a power supply, and an Ethernet cable (recommended for reliability, though Wi-Fi works too). You'll also need a computer to download software and a way to access the Pi's terminal, either with a monitor and keyboard or via SSH.
What You'll Need
- Raspberry Pi (3B, 3B+, 4, 5, or Zero 2 W)
- MicroSD card (8GB or larger, Class 10 recommended)
- Power supply for your Pi (5V, 2.5A or better)
- Ethernet cable (recommended) or Wi-Fi
- A computer (Windows, Mac, or Linux) to write the SD card
- Monitor and keyboard (only if you're not using SSH)
- An SD card reader (if your computer doesn't have one built-in)
Step-by-Step
- Download Raspberry Pi OS. On your computer, go to the official Raspberry Pi website and download the Raspberry Pi Imager software. Install it, then open it. Choose your Pi model and select the operating system. For Pi-hole, use the Lite version (no desktop) to keep things lightweight and stable. Click 'Choose OS' → 'Raspberry Pi OS (other)' → 'Raspberry Pi OS Lite (64-bit)'. Then select your SD card and click 'Write'. Wait for it to finish, then remove the card.
- Enable SSH (optional but recommended). After writing the image, the SD card will appear as a drive on your computer. Create an empty file named
ssh(no extension) in the root of the boot partition. This enables SSH on first boot, so you can control the Pi remotely without a monitor. - Boot the Pi. Insert the SD card into the Pi, connect the Ethernet cable (or set up Wi-Fi later), and plug in the power. Wait about a minute for it to boot. If you have a monitor, you'll see the login prompt. The default username is
piand password israspberry(you'll change this soon). If you enabled SSH, find the Pi's IP address from your router's admin page or use a network scanner app. - Connect to the Pi. If you're using SSH, open a terminal on your computer and type:
ssh pi@<IP_ADDRESS>(replace with the Pi's IP). Enter the password when prompted. If you're using a monitor, just log in locally. - Update the system. Run the following commands to update the package list and upgrade installed software:
sudo apt updatethensudo apt upgrade -y. This ensures you have the latest security patches and software versions. - Change the default password. For security, change the default password by running
passwd. You'll be prompted for the current password, then the new one. This is critical if the Pi is exposed to your network. - Set a static IP address. Pi-hole needs a fixed IP so devices can always find it. Edit the DHCP configuration file:
sudo nano /etc/dhcpcd.conf. Add the following lines at the end (replace the example IP with one that fits your network, e.g., 192.168.1.50):interface eth0 static ip_address=192.168.1.50/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
Save withCtrl+X, thenY, thenEnter. Reboot withsudo reboot. After reboot, reconnect via SSH using the new IP. - Install Pi-hole. Run the official installation script:
curl -sSL https://install.pi-hole.net | bash. This downloads and runs the installer. Follow the prompts: choose your upstream DNS provider (e.g., Google or Cloudflare), select the blocklists (the default is fine), and set the admin web interface password. Write down this password—you'll need it to log into the dashboard. - Finish the installer. When the installer finishes, it will display the Pi-hole IP address and the admin URL (usually
http://<PI_IP>/admin). Note these down. The installation may take a few minutes. - Access the dashboard. On any computer on your network, open a web browser and go to
http://<PI_IP>/admin. Log in with the password you set. You'll see the Pi-hole dashboard showing total queries, blocked queries, and top clients. - Configure your router to use Pi-hole. This is the crucial step to make Pi-hole block ads for your entire network. Log into your router's admin page (usually at 192.168.1.1 or 192.168.0.1). Find the DHCP settings (often under 'LAN' or 'Network'). Set the DNS server to the Pi's static IP address (e.g., 192.168.1.50). Save the settings. Your router will now tell all devices to use Pi-hole for DNS.
- Renew DHCP leases. Devices that already have an IP address may still use the old DNS. To force them to update, either restart your router or wait for the DHCP lease to expire (usually a few hours). You can also manually set DNS on individual devices for immediate effect.
- Verify it's working. Visit a website that has ads (like a news site) and you should see empty spaces where ads were. To confirm, check the Pi-hole dashboard—you'll see queries being blocked in real time. You can also run a command on the Pi:
pihole -q example.comto test if a domain is blocked.
Common Mistakes
- Forgetting to set a static IP. If your Pi's IP changes, devices will lose DNS resolution. Always set a static IP before installing Pi-hole.
- Using the wrong DNS in the router. Make sure you enter the Pi's IP, not the router's IP, in the DHCP DNS field.
- Not updating the system first. An outdated Pi can have compatibility issues with the installer. Always run
sudo apt update && sudo apt upgradefirst. - Enabling IPv6 without proper configuration. If your network uses IPv6, Pi-hole may not block IPv6 ads unless you also configure the IPv6 DNS. Check your router settings for IPv6 DNS and set it to the Pi's IPv6 address (if available) or disable IPv6 on the Pi.
- Blocking too much. Some blocklists are aggressive and can break websites. Use the default lists first, then add more only if needed.
Tips
- Use a wired connection. Ethernet is more reliable than Wi-Fi for a DNS server. If you must use Wi-Fi, make sure the signal is strong.
- Backup your Pi-hole configuration. The Pi-hole has a built-in backup feature:
pihole -a -tcreates a teleporter backup file. Store it on your computer for easy recovery. - Update Pi-hole regularly. Run
pihole -upto update Pi-hole and its blocklists. You can also set up a cron job to update automatically. - Customize blocklists. You can add your own blocklists from sources like Firebog or the Pi-hole community. Use the 'Adlists' section in the dashboard.
- Use the API. Pi-hole has a REST API that lets you integrate with home automation systems like Home Assistant to show stats or control blocking.
Troubleshooting
- Pi-hole is installed but nothing is blocked. Check that your router is actually using the Pi as DNS. On a computer, run
nslookup doubleclick.com(or any ad domain). If it returns an IP, Pi-hole is not in the path. Re-check your router settings and restart devices. - Can't access the admin dashboard. Ensure you're using the correct IP and port (default is 80). Try
http://<PI_IP>/admin. If it fails, check that the Pi's web server is running:sudo systemctl status lighttpd. If not, start it withsudo systemctl start lighttpd. - Devices lose internet after setting DNS. This usually means the Pi's firewall is blocking DNS. Allow DNS on the Pi:
sudo ufw allow 53(if using UFW). Also ensure the Pi's IP is correct in the router. - Some ads still appear. Pi-hole can't block ads that come from the same domain as the content (e.g., YouTube ads). Also, some apps use hardcoded DNS. Use the 'Query Log' in the dashboard to see which domains are being requested and add them to the blocklist manually if needed.
- Pi-hole is slow to respond. Check your upstream DNS provider. Sometimes a slow provider can cause delays. Try switching to a faster one in the dashboard under 'Settings' → 'DNS'. Also, ensure the Pi has enough resources—close other apps if running.
Frequently Asked Questions
- Will Pi-hole slow down my internet? No, it usually speeds it up because it blocks ads before they load, reducing data transfer. The DNS lookup is cached, so repeated requests are faster.
- Can I use Pi-hole with a VPN? Yes, but you need to configure the VPN to use Pi-hole as its DNS server. Many VPN setups allow custom DNS. Alternatively, you can install Pi-hole on the same server as your VPN.
- Does Pi-hole block all ads? It blocks most ads, but not those that are served from the same domain as the content (e.g., YouTube pre-roll ads). It also can't block ads in apps that use hardcoded IP addresses instead of DNS.
- Can I whitelist a domain? Yes. In the dashboard, go to 'Whitelist' and enter the domain. You can also use the command line:
pihole -w example.com. - Will Pi-hole work with IPv6? Yes, Pi-hole supports IPv6, but you need to configure your router to use the Pi's IPv6 address as DNS. If your network doesn't use IPv6, you can disable it on the Pi to avoid issues.
- Can I run Pi-hole on other hardware? Yes, Pi-hole can run on any Linux system, including Docker containers, old PCs, or cloud servers. The setup is similar, but you'll need to adjust the static IP configuration.