Tuesday, February 12, 2019

Pi-hole - Worth it?


Warning!
In this post I am going to write things very simply, not going into much details because that will be extremely boring but do not get alarmed, I will add some links where you can learn about all these topics in details if you so desire.

In this day and age, we pass a lot of time browsing the internet and the sites we browse contains a lot of ads. In many cases sites are so filled with ads that it makes the experience painful or makes it very hard to find a particular information. Don’t get me wrong though, I don’t mind few ads on a website where people can get information for free and the site owner gets paid by the advertiser. I am fine with that but vast majority of websites these days just want to serve ads not information. To circumvent that Pi-hole can be used.

What is Pi-hole? 



It is a Linux network-level advertisement and internet tracker blocking application. It is a DNS Sinkhole intended to be used on private network and runs great on embedded systems with network capability such as a single board computer. It can be used on other machines running Linux as well. Before talking about this DNS Sinkhole let’s look at what DNS is and why it is relevant to us in terms of blocking ads.
To get more information you can visit their website.

Intro to DNS?
DNS stands for Domain Name Service and it is often compared with a telephone guide for the internet. In a basic telephone guide, you would look up some name and it will tell you the number or address of some sort where you can find what you are looking for. DNS is kind of same except it tells you the actual address of websites that you are looking for. When you type in something like www.google.com on your web browser it asks the DNS server what the address of this site is. The DNS server might reply 74.125.68.147. This is the address of google. If you type in this to your web browser you will get to google as well. Now that we know this let’s see how all of these fits with Pi hole and ad blocking.

How does Pi-hole Works?
Usually your ISP will provide you with a DNS server and in case you have a home network your router might have another DNS server that will point out towards the DNS server of the ISP. In case of Pi-hole, it will act as a DNS server between your device and the DNS server you are trying to reach. So, any query you have it will first go to the Pi-hole then it will be redirected towards the DNS server. What often happens is website designer dedicates a space for ads where an ad provider server will supply ads. That provider has its own address. When the said website tries to load that ad it also requests queries to the DNS server for that ad serving server but as now all queries go through the Pi-hole it just blocks known ad serving addresses. Thus, you don’t see some ads. It won’t block all the ads, because ads are often served by the same server that you are getting your information from.
For example, the top blocked domain is due to the android app called Battery doctor which is on my tablet (Nexus 7 2013) and you can see how many times this app has queried for ads from this site. Come to think of it, I’m pretty sure this app is just destroying the battery by doing this kind of thing on the back ground.

How to install it?
Let’s install it on a Raspberry Pi, it is Pi-hole after all. Although you can install it on any Linux machine you like.

Required Hardware and software:
1.       Raspberry Pi, I’m using a Pi2 model B.
2.       A Samsung 32GB micro SD.
3.       Huawei 5V 1A mobile phone charger.
4.       Ethernet cable to connect with the Router.
5.       Raspbian Operating system.


Procedure:
From Terminal or SSH type in
curl -sSL https://install.pi-hole.net | bash
 




This will start the step by step process of installing Pi-hole.
It will ask for static IP and it is better to provide one. I will talk a little more about this in a minute.
Install web interface.
Install logging.
Get both IPv4 and IPv6 filtering.
For Upstream DNS provider use whatever you want, maybe one that is provided by your router or your ISP or google. This will be the DNS server Pi-hole use after filtering the Queries you got from your devices.
As it finishes do make sure to copy the password because you will need it to login through the Web interface.

Updating:

Updating Gravity:
Gravity is the list of blocked domains. Going to Tools>Update Gravity it can be easily updated from the web-based interface. 



However, if you want to update the whole system and the web interface you have to do it from Terminal.

pihole -up is all you need to type. (Do make sure to run update and upgrade before that)

 
After the update process is finished it will show the version number of the updated modules.


Configuration on the client end:
PC:
To use Pi-hole on your computer simply go to Network and Internet Settings>Change adapter options>Right click and Properties of the adapter in use>Internet protocol V4>Use the following DNS server addresses.
In here type in the address of the Pi hole machine which is in my case 192.168.0.100.
 




Android:

Note:
1.       It is better to provide a static IP for your Pi-hole machine as other systems depend on the IP address of this machine which might change as the DHCP server on the router rotates IP addresses. Simple DHCP Address reservation will work just fine.
2.