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 origin 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 dashboard 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 distribution you should have it up and running.

Now for the tricky bit some ISP’s don’t let you change which dns servers you point at on the provided routers (I’m looking at you virgin). This isn’t 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.

Fortunately 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
Older article
Ansible Vs Cygwin