Raspberry Pi

How to set up Pi-hole with Unbound on a Raspberry Pi

Raspberry Pi12 min read

Updated

By Sanjiv Shukla

On this page
A blue shield with a house blocking red arrows marked with Google, Facebook and Amazon logos, captioned Pi-hole + Unbound

Updated 18 Nov 2026: checked every step against the current Pi-hole v6 and Raspberry Pi documentation. Fixed the install commands, which did not run as printed, replaced the static IP step that no longer applies to Raspberry Pi OS, switched to Pi-hole’s current Unbound config and added checks for DNS interception, DNSSEC and the Pi-hole upstream.

Pi-hole blocks ads and trackers for every device on your network by refusing to look up their domains. Unbound, installed on the same Raspberry Pi, answers every other lookup itself, starting from the internet’s root servers, so no public DNS provider such as Google or Cloudflare sees your queries. The setup has five steps: flash Raspberry Pi OS Lite, install Pi-hole, install and configure Unbound on port 5335, point Pi-hole at 127.0.0.1#5335, then make your router hand out the Pi’s address as the DNS server.

The steps follow Pi-hole’s and Raspberry Pi’s official documentation, checked on 18 Nov 2026, when the current Pi-hole release was Core v6.6 (11 Nov 2026). We have not run this setup on a Raspberry Pi for this update.

What is Pi-hole?

Pi-hole is a DNS sinkhole. DNS works like the internet’s phonebook: when you type kextcache.com into your browser, your device asks a DNS server for the site’s IP address, then connects to it.

With Pi-hole, your whole network uses the Pi as its phonebook. When a device asks for a domain on Pi-hole’s blocklists, such as an ad or tracking server, Pi-hole doesn’t hand back the real address. The request goes nowhere, so the ad never loads and the tracker never reports back.

Because the blocking happens at the DNS level, it covers in-app ads on your phone, ads on your smart TV and every other device on your network, with no software to install on them.

Best Raspberry Pi for Pi-hole in 2026

Why add Unbound?

On its own, Pi-hole forwards every lookup it doesn’t block to an upstream DNS provider such as Google (8.8.8.8) or Cloudflare (1.1.1.1). These services are fast and reliable, but whichever one you pick sees nearly every site you visit.

Unbound is a validating, recursive and caching DNS resolver that you run yourself. Instead of asking Google, it asks a root server who handles .net, asks that server who handles pi-hole.net, then asks pi-hole.net’s own name servers for the address.

With both running, Pi-hole drops the lookups you don’t want and Unbound resolves the rest. Each server Unbound contacts sees only its part of the path: Pi-hole’s docs give the example that Google’s DNS servers are asked only when you visit a Google site. Unbound also verifies DNSSEC signatures and discards answers that fail, and both programs cache answers, so repeat lookups are answered on your own network.

The first lookup of a new domain is slower, because Unbound has to walk the whole path. Pi-hole’s docs say the first request to a new top-level domain can take up to a second, and later requests under the same one usually take under 0.1 seconds. Unbound also talks to those servers over ordinary, unencrypted DNS on port 53, which some ISPs and routers intercept and answer themselves. Step 3 starts with a test for that.

What you need

  • Hardware:
    • Any Raspberry Pi with a network connection. Pi-hole needs at least 512 MB of RAM and 2 GB of free storage (4 GB recommended). If you’re buying one, see which Raspberry Pi to pick for Pi-hole.
    • A quality microSD card (16 GB or larger is plenty).
    • A reliable power supply for your Pi model.
    • An Ethernet cable (a wired connection is highly recommended for a DNS server’s stability).
  • Software:

Step 1: Prepare the Raspberry Pi

First, we need a clean, updated operating system.

From the official docs: Raspberry Pi’s Imager guide and DHCP and static IP guide, and Pi-hole’s prerequisites, checked 18 Nov 2026. Not run by us.

  1. Flash Raspberry Pi OS Lite: In Raspberry Pi Imager, choose your Pi model, then Raspberry Pi OS Lite (64-bit), then your SD card. A Pi Zero W runs only the 32-bit version. In the Customisation tab, set a hostname and a username and password, add Wi-Fi only if you can’t use Ethernet, and turn on Enable SSH in the Remote Access subtab.

  2. Boot and connect: Insert the SD card into your Pi, connect the Ethernet cable, and power it on.

  3. Find its IP and SSH in: Find the Pi’s IP address from your router’s admin page. Now, connect to it via SSH:

    bash
    ssh your_username@your_pi_ip_address
  4. Give the Pi a fixed IP address: A DNS server must have a predictable address. On your router, set a DHCP reservation (sometimes called a static lease) for the Pi. Raspberry Pi’s docs recommend this over setting a static IP on the Pi itself, and Pi-hole’s docs say a reservation works fine.

    Older guides set the address in /etc/dhcpcd.conf, but since the Bookworm release Raspberry Pi OS uses NetworkManager for networking, so that method no longer applies. If your router can’t reserve addresses, Raspberry Pi’s docs say you can set a static IP on the Pi with nmcli. Choose an address outside the router’s DHCP range that no other device uses.

    Reboot the Pi with sudo reboot so it picks up its reserved address.

Step 2: Install Pi-hole

With our Pi configured, it’s time to install the main software.

From the official docs: Pi-hole’s basic install page and its installer script, basic-install.sh, checked 18 Nov 2026. Not run by us.

  1. Run the installer: SSH back into your Pi at its new address and run Pi-hole’s one-step installer:

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

    Piping a script into bash runs it before you can read it. If you’d rather read it first, Pi-hole’s docs offer this alternative:

    bash
    wget -O basic-install.sh https://install.pi-hole.net
    sudo bash basic-install.sh
  2. Follow the wizard: The installer asks, in this order:

    • to confirm that the Pi has a static IP address (done in step 1);
    • which network interface to use, if the Pi has more than one (choose eth0);
    • for an upstream DNS provider (choose any for now; Unbound replaces it in step 4);
    • whether to add the suggested blocklist, StevenBlack’s Unified Hosts List (yes);
    • whether to turn on query logging, and which privacy mode to use for the logs.

    Pi-hole v6 has its web interface built in, so the installer no longer asks whether to install one.

  3. Save the password: The final screen shows the address of the web interface (http://your_pi_ip/admin) and a randomly generated admin password. Save this password! You can change it later with pihole setpassword.

At this point, you have a working Pi-hole. You could stop here, but to resolve DNS yourself, install Unbound next.

Step 3: Install and configure Unbound

Now we set up our personal recursive DNS resolver.

From the official docs: Pi-hole’s Unbound guide, last updated 12 Sep 2026, checked 18 Nov 2026. Not run by us.

  1. Check that the Pi can reach a root server: Pi-hole’s installer has already added dig. Ask a.root-servers.net (198.41.0.4) for the root zone, first over UDP and then over TCP:

    bash
    dig @198.41.0.4 . NS +norec +time=3
    dig @198.41.0.4 . NS +norec +tcp +time=3

    In both answers, the flags: line should include aa and not ra. If you see ra instead, or the TCP query times out, your ISP, your router or a carrier-grade NAT is intercepting or blocking DNS. Pi-hole’s docs advise fixing that before you install Unbound.

  2. Install Unbound:

    bash
    sudo apt update
    sudo apt install unbound -y

    When you install Unbound with apt, it gets its list of root servers from the dns-root-data package, and apt keeps that list up to date, so you no longer need to download root.hints yourself.

  3. Create the Unbound configuration: We’ll create a new configuration file specifically for Pi-hole.

    bash
    sudo nano /etc/unbound/unbound.conf.d/pi-hole.conf

    Paste Pi-hole’s suggested configuration into the file (two long comments are shortened here). It makes Unbound listen only for requests from Pi-hole on the same machine, on port 5335, over both UDP and TCP, verify DNSSEC signatures and apply a few security and privacy settings.

    text
    server:
        # If no logfile is specified, syslog is used
        # logfile: "/var/log/unbound/unbound.log"
        verbosity: 0
    
        interface: 127.0.0.1
        port: 5335
        do-ip4: yes
        do-udp: yes
        do-tcp: yes
    
        # May be set to no if you don't have IPv6 connectivity
        do-ip6: yes
    
        # You want to leave this to no unless you have *native* IPv6. With 6to4 and
        # Terredo tunnels your web browser should favor IPv4 for the same reasons
        prefer-ip6: no
    
        # Use this only when you downloaded the list of primary root servers!
        # If you use the default dns-root-data package, unbound will find it automatically
        #root-hints: "/var/lib/unbound/root.hints"
    
        # Trust glue only if it is within the server's authority
        harden-glue: yes
    
        # Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS
        harden-dnssec-stripped: yes
    
        # Don't use Capitalization randomization as it known to cause DNSSEC issues sometimes
        # see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details
        use-caps-for-id: no
    
        # Reduce EDNS reassembly buffer size.
        edns-buffer-size: 1232
    
        # Perform prefetching of close to expired message cache entries
        # This only applies to domains that have been frequently queried
        prefetch: yes
    
        # One thread should be sufficient, can be increased on beefy machines.
        num-threads: 1
    
        # Ensure kernel buffer is large enough to not lose messages in traffic spikes
        so-rcvbuf: 1m
    
        # Ensure privacy of local IP ranges
        private-address: 192.168.0.0/16
        private-address: 169.254.0.0/16
        private-address: 172.16.0.0/12
        private-address: 10.0.0.0/8
        private-address: fd00::/8
        private-address: fe80::/10
    
        # Ensure no reverse queries to non-public IP ranges (RFC6303 4.2)
        private-address: 192.0.2.0/24
        private-address: 198.51.100.0/24
        private-address: 203.0.113.0/24
        private-address: 255.255.255.255/32
        private-address: 2001:db8::/32

    Press Ctrl+X, Y, and Enter to save.

  4. Turn off the resolvconf entry for Unbound: On Debian Bullseye and later, a service called unbound-resolvconf writes Unbound’s address into /etc/resolv.conf without the 5335 port, which causes unexpected behaviour for Pi-hole and Unbound. Pi-hole’s docs mark this step as required on those releases, and current Raspberry Pi OS is based on Debian Trixie. The first command shows whether the service is active. The other three disable it and stop resolvconf from generating resolvconf_resolvers.conf again:

    bash
    systemctl is-active unbound-resolvconf.service
    sudo systemctl disable --now unbound-resolvconf.service
    sudo sed -Ei 's/^unbound_conf=/#unbound_conf=/' /etc/resolvconf.conf
    sudo rm /etc/unbound/unbound.conf.d/resolvconf_resolvers.conf
  5. Restart and test: Restart the Unbound service and test it to make sure it can resolve domains.

    bash
    sudo service unbound restart
    dig pi-hole.net @127.0.0.1 -p 5335

    You should see a successful response with a status of NOERROR. The first query may be slow; later ones should be quick.

  6. Check DNSSEC:

    bash
    dig fail01.dnssec.works @127.0.0.1 -p 5335
    dig +ad dnssec.works @127.0.0.1 -p 5335

    The first should return SERVFAIL and no IP address. The second should return NOERROR, an IP address and ad in the flags: line, which means Unbound validated the answer with DNSSEC.

This is the final step in our software setup. We need to tell Pi-hole to stop using public DNS servers and start using our own Unbound resolver.

From the official docs: Pi-hole’s Unbound guide, checked 18 Nov 2026. Not run by us.

  1. Log in to your Pi-hole web interface (http://your_pi_ip/admin).
  2. Go to Settings > DNS.
  3. Untick every upstream DNS server.
  4. Under Custom DNS servers, enter 127.0.0.1#5335. This tells Pi-hole to send its queries to the Unbound service running on the same machine on port 5335.
  5. Click Save & Apply.

To confirm that Pi-hole now uses Unbound, look up a domain through Pi-hole and read its log:

bash
dig en.wikipedia.org @127.0.0.1
sudo tail /var/log/pihole/pihole.log

The log should show the query forwarded en.wikipedia.org to 127.0.0.1#5335, followed by the reply.

Step 5: Point your network at Pi-hole

The final step is to make your entire network use your new creation.

From the official docs: Pi-hole’s post-install page, checked 18 Nov 2026. Not run by us.

  1. Log in to your home router’s administration page.
  2. Find the DHCP or LAN settings.
  3. Look for an option related to DNS Server.
  4. Set the Primary (and only) DNS Server to the fixed IP address of your Raspberry Pi (for example, 192.168.1.10).
  5. Save the settings. Your router may need to restart.

Once your router is back online, devices on your network will automatically start using Pi-hole for all DNS requests. You may need to disconnect and reconnect devices to the network for the change to take effect immediately.

If your router can’t change the DNS server it hands out, turn off DHCP on the router and use Pi-hole’s built-in DHCP server instead. As a last resort, set the Pi as the DNS server on each device by hand.

Check that it works

Browse a few ad-heavy sites, then log in to your Pi-hole web interface and watch the query log, where blocked requests show up as they happen.

Pi-hole is often the first project on a new home server, and our guide to building a home server covers what to run next. To reach your network from outside, set up a VPN to your home network. For other jobs the same board can do, see our list of Raspberry Pi 5 uses.

Changes

  • 18 Nov 2026: fixed the Pi-hole install command, which had link markup inside the code block and did not run as printed. Replaced the /etc/dhcpcd.conf static IP step with a DHCP reservation, because Raspberry Pi OS now uses NetworkManager.
  • 18 Nov 2026: replaced the Unbound config with Pi-hole’s current one. Removed use-caps-for-id: yes, which Pi-hole’s docs say can cause DNSSEC issues, the active log file line, a duplicate so-rcvbuf, the one-hour minimum cache time and the manual root.hints download.
  • 18 Nov 2026: added the root server, DNSSEC and upstream checks, the unbound-resolvconf step and the Pi-hole v6 menu names and installer questions.
Written by

Sanjiv Shukla

Sanjiv Shukla writes about open-source software, self-hosting, home servers, Linux and new technology. He turns complex topics into practical steps that readers can follow and build on, with the aim of making technology approachable in everyday life.

Comments

No comments yet.

    Read more