Pi-hole, to Block Away Annoying Ads

Create your own DNS sinkhole to block ads on all your devices at home

Anuradha Wickramarachchi
An Idea (by Ingenious Piece)

--

Advertising has become so prominent that most of us see too many ads. As they say “If you’re not paying for something, you probably are the product”. So all that free services care is the amount of advertising you expose yourself for them to show ads and make income. It is not a very bad thing, yet us geeks can have a work-around, so why not give it a try!

Photo by Joshua Earle on Unsplash

In this article, I will explain in detail how to set up Pi-hole, which is a DNS sinkhole, that will intercept your name queries and block that are seemingly undesired or considered as advertising.

Setting Up the Raspberry-Pi (RPi)

As the name suggests, Pi-hole is typically deployed in an RPi device. In this article, I will be using RPi-zero wireless single-board computer (SBC). This device is literally less than $20 with a nice enclosure and you can let it run indefinitely once you configure it.

  • Go to dietpi.com and download a version that fits your board. In my case, it is the 32bit version of DietPi.
Screenshot by Author from https://dietpi.com/
Flashing DietPi image (Screenshot by Author)
  • I will change the settings in dietpi.txt file in the flashed sd card as follows (as I am using WiFi, if not leave it as it is).
AUTO_SETUP_NET_ETHERNET_ENABLED=0
AUTO_SETUP_NET_WIFI_ENABLED=1
  • Update the dietpi-wifi.txt as follows.
aWIFI_SSID[0]="YOUR_SSID"
aWIFI_KEY[0]="YOUR_PASSWORD"
  • Now insert the SD card into the RPi and boot it up
  • After a short while, you’ll see the DietPi device in your router’s clients list.
Screenshot by Author

Now, you need to ssh into the running DietPi and do some pre-configurations. Password for root of DietPi is dietpi by default.

ssh root@<IP ADDRESS OF DIET PI>

You’ll be shown with a license statement, press Enter and continue. Be patient as the new few step will take some time to finish. Next, you’ll be asked to either opt-in out from their surveys. The RPi, will update the OS and prompt for you to change the password, disable serial console (not so relevant in our case) and then you’ll be prompted with an options menu, select Install and hit OK. You are perfectly fine to install the minimal version (when prompted).

Now the setting up of the RPi device is complete. Now let’s start the Pi-hole installation.

Setting up Pi-hole in RPi

Pi-hole installation is available at Pi-hole GitHub page. You can run the following command to install everything at once. Copy this and paste in the terminal to begin the installation.

curl -sSL https://install.pi-hole.net | bash
Pi-hole installation terminal (Screenshot by Author)
  • Click OK for the next few prompts. At the following screen, pick Cloudflare (as we probably want to avoid ad-savvy DNS services).
Screenshot by Author
  • Then leave the blockers as it is and select OK, we shall edit the lists later on.
  • In the following screen select NO, as we will set a static IP later on.
Screenshot by Author
  • Then when you’re asked to enter the static IP address, first find the DHCP IP range from your Router page (192.168.1.1 web admin panel)
Screenshot by Author
  • Here DHCP range is between 100 and 199, so I will use 192.168.1.55 as my IP for Pi-hole. We need to set the same IP address to our name server. It should look like follows from the router admin panel. Then hit save.
Screenshot by Author
  • Now my setting will be set to be as follow in the installation terminal of Pi-hole.
Screenshot by Author
  • Select the WebAdmin and webserver to be installed in the coming screens. Rest of the options can be left as it is in the next screens. It’ll take some time to install everything. So be patient once again.
  • Finally, you’ll see a screen as follows, be sure to save the password shown (I have redacted that using a black box).
Screenshot by Author

Setting up DietPi Static IP Address

In order to make sure that DietPi will assign itself the proper IP we gave in Pi-hole installation, we shall do the following steps.

  • Enter the following command in the terminal
dietpi-config
  • Go to option 7 : Network Options: Adapters
  • Then scroll to WiFi (or Ethernet based on your network connection)
  • Now hit on DHCP/STATIC IP, then it should look like following (update gateway it is different from your router’s). Then hit Apply!
Screenshot by Author

Now the connection will automatically drop as DietPi changes its IP address. This happens when you see the following message.

[  OK  ] DietPi-Config | Dropping connections, please wait...

So SSH to the RPi again using the newly assigned static IP address, which is 192.168.1.55 for me.

The Pi-hole Admin Panel

Now our installations and setups are complete. We now have to open the Pi-hole admin panel and make few tweaks. For that go to;

192.168.1.55/admin

Then click login on the left side pane. You’ll need to use your password that was shown in the previous step (the one I had redacted in the black box).

Now go to settings from the left pane and then click Adlist. Then click on Adlist group management in order to make changes to block lists.

https://hosts.oisd.nl/ is one such curated set of URLs that needs blocking. Copy this URL and paste in the Adlist address box. You’ll find few more at https://firebog.net/ too. Go to that website and copy URLs (that aren’t strickenthrough) then paste on the address box again.

Screenshot by Author

Now click on the circled link and then click update to make the changes take effect. Wait until it completes!

Just to make sure that the new DNS is working, have a look at your computers DNS server (You are probably required to renew your DHCP lease in your computer, or simply disconnect and connect again). I have the following visible.

Screenshot by Author

So we are all set!. I hope you found this useful and a cheap solution to enjoy uninterrupted entertainment.

Happy reading! :)

--

--