Photo of Nils Streedain

Nils Streedain


Pi-Hole and Unbound logos over a gradient

Setting Up Pi-hole with Unbound

How to set up Pi-Hole With Unbound and AutoUpdating Blocklists

Page view count

May 17, 2021
Updated Oct 04, 2021

By Nils Streedain

Before getting started:

  • Create a fresh install of Raspbian (or your prefered distro) with ssh enabled
  • Connect your Raspberry Pi (or whatever computer you’re using) to your network
  • ssh into the Pi

Update Raspberry Pi

sudo apt update
sudo apt full-upgrade

Change Raspberry Pi Password



sudo raspi-config

Set Raspberry Pi Country (raspi-config > Localisation Options > WLAN Country)

Change Raspberry Pi Hostname (raspi-config > System Options > Hostname)

Setup Pi-Hole

Install Pi-Hole and follow the steps in the user interface

sudo curl -sSL | bash

Change default Pi-Hole password

sudo pihole -a -p

Setup Unbound

Install Unbound

sudo apt install unbound

Update the list of primary root servers

wget -qO- | sudo tee /var/lib/unbound/root.hints

Configure unbound

Open unbound configuration

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

Paste the following:

    # If no logfile is specified, syslog is used
    # logfile: "/var/log/unbound/unbound.log"
    verbosity: 0

    port: 5335
    do-ip4: yes
    do-udp: yes
    do-tcp: yes

    # May be set to yes if you have IPv6 connectivity
    do-ip6: no

    # 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 for further details
    use-caps-for-id: no

    # Reduce EDNS reassembly buffer size.
    # Suggested by the unbound man page to reduce fragmentation reassembly problems
    edns-buffer-size: 1472

    # 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. In reality for most users running on small networks or on a single machine, it should be unnecessary to seek performance enhancement by increasing num-threads above 1.
    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: fd00::/8
    private-address: fe80::/10

Finally, restart unbound

sudo service unbound restart

Use the web admin panel to change the Pi-Hole upstream DNS to for IPv4 and ::1#5335 for IPv6

Update root.hints monthly (Not Really Needed)

Create a monthly cron job called updateroothints

sudo nano /etc/cron.monthly/updateroothints

Paste the following:


# update unbound root list
wget -qO- | sudo tee /var/lib/unbound/root.hints

Make it executable

sudo chmod +x /etc/cron.monthly/updateroothints

Setup Auto-Updating BlockLists

Install pihole-updatelists and it’s dependacies

sudo apt-get install php-cli php-sqlite3 php-intl php-curl
wget -O - | sudo bash

Configure pihole-updatelists

sudo nano /etc/pihole-updatelists.conf

Blacklists (exact):

  • Very Safe - No false positive (What I Recommend):
  • Somewhat Safe - Rare false positives (What I use):

Blacklists (regex):

  • Some false positives, whitelist recommended:
  • Blocks TikTok domains:

Whitelist (exact):

  • Recommended Whitelist:
  • My Whitelist:

Whitelist (regex):

  • My Whitelist:

Update pi-hole lists

sudo pihole-updatelists

Update pi-hole lists daily

Create a daily cron job called updatelists

sudo nano /etc/cron.daily/updatelists

Paste the following:


# update Pi-Hole lists
sudo pihole-updatelists

Make it executable

sudo chmod +x /etc/cron.daily/updatelists