Adblock, System-Wide, without Plugins… Pi-Hole!

This is absolutely awesome. I just came across Pi-Hole, a DNS based ad blocker that you can install on a Raspi or just some Linux box you may have around.

Basically, what you do is this: You log as root onto your Raspi or Linux box (I’ve tested it with Ubuntu 16.04 LTS; it did not work on an older 12.04), and just enter:

curl -L | bash

A much more detailed instruction, with lots of screen shots, is here.

Some packages are going to be installed, and later you just point your device’s DNS server to be the IP address of that Raspi or Linux box where you installed Pi-Hole. Since I have a router with OpenWRT, I have dnsmasq on it and hence have modified its dnsmasq.conf to have its server= statement point to the IP of the Pi-Hole box.

What then happens is that every DNS request will be routed through the Pi-Hole box, and if it is from a known advertiser, it will just be blocked. The net effect is, that all your devices will be mostly completely ad free. Since the only traffic going through that box is DNS requests, the solution is very fast, compared to web proxies.

Once installed, you can point your browser to this (local) URL to see a nice dashboard about Pi-Hole’s performance:

As you can see, the vast majority of my requests come from, which is my OpenWRT router that is now redirecting the DNS requests it gets – which means mostly all – through the Pi-Hole box.

For more technically inclined, here is the forum where Pi-Hole users discuss.

If you want to have Pi-Hole automatically update its blacklists, you can put this file as pihole-update into /etc/cron.daily:


/usr/local/bin/pihole -up

Then make that file executable:

chmod 755 /etc/cron.daily/pihole-update

Here is a blog post of some other user who has posted some more details on the topic.

As a nice extra, if you have a Mac, and install BitBar on it, you can then add this plugin, and further more see nicely what Pi-Hole is doing for you:


The above menu is actually using a simple Python script to populate. I’ve updated that script so that you can now also directly enable / disable Pi-Hole. Here is what it does:

Here is the updated script (notice that I’ve changed, in line 20, the URL of the Pi-Hole to how it announces itself on the net independent of the IP address you gave to it; lines 35-37 are those that I have added to provide for enabling and disabling of the service):

# -*- coding: utf-8 -*-
# Pi-hole status
# v1.0
# Siim Ots
# siimots
# Show your Pi-Hole (Raspberry Pi adblocker) status. Todays blocked ads, DNS queries and number of domains in block list.
# pi-hole,python

import urllib2
import json

# If you have UTF-8 problems then uncomment next 3 lines
#import sys

# Change to Your Pi-Hole Admin Console URL
pihole = "http://pi.hole/admin/"

    url = pihole + "api.php"
    result = urllib2.urlopen(url, timeout = 5).read()
    json = json.loads(result)
    print "🌍"
    print "---"
    print "Ads blocked:"
    print json['ads_blocked_today'] + "| href=" + pihole
    print "DNS queries:"
    print json['dns_queries_today'] + "| href=" + pihole
    print "Domain list size:"
    print json['domains_being_blocked'] + "| href=" + pihole
    print "---"
    print "Disable | href=" + pihole + "?disable"
    print "Enable | href=" + pihole + "?enable"
    print "---"

    print "❌"
    print "---"
    print "Pi-Hole not found | color=red"
    print "---"

And, as an uber-cool hack, should you use (unlike me) an actual raspi for this, here is how you can activate/deactivate Pi-Hole with an actual hardware button.