Ablocking with Pi Hole

with tags adblocking pi dnsmasq -

So like most people I really dislike adverts on websites, and while it’s nice and simple to throw ublock orign on to a browser when running on a desktop/laptop once tablets/phones/internet enables fridges it becomes a bit more tricky to get rid of the obnoxious adverts.

This is where pi-hole comes in handy. Not only does it block adverts for your entire network but you also get a fancy looking dashbord showing all sorts of metrics and all you have to do is (not so) simply repoint your the dhcp service to use pi hole on a router to use it instead of your ISP provided service.

Assuming you have a spare Raspberry pi or other device thats always going to be on and connected to your lan, all you have to is run (yes we all know piping random shell scripts to bash is not a good idea)

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

And as long as you’re running a reasonably standard debian or redhat based distribuion you should have it up and running.

Now for the tricky bit some ISP’s dont let you change which dns servers you point at on the provieded routers (I’m looking at you virgin). This isnt the end of the world as given that we’re going to be using the pi for dns anyway so it needs to be up and running if we want to have a usable internet connection so we might as well use it for dhcp as well.

Fortunatly Pi-Hole does most of the setup of dnsmasq for us and we can get away with dropping a config file into /etc/dnsmasq.d/02.dns.conf.

dhcp-range=192.168.1.<startofrange>,192.168.0.<endofrange>,<hostmak>,<leasetime ie: 12h>
dhcp-option=option:router,<ip of router>

All that’s left, is to disable the dhcp service on your isp provied router and away you go.

curl pi.hole/admin/api.php
{
  "domains_being_blocked": "103,819",
  "dns_queries_today": "9,108",
  "ads_blocked_today": "1,057",
  "ads_percentage_today": "11.6"
}
Written by
Later article
Ansible Vs Cygwin