Jack Hutchison – Blog Page

Projects & Blog on Misc topics written by someone in their 30s

Pi-Hole DNS Ad-Blocking Project

PROBLEM

The number of pop-up ads I seemed to be getting when browsing to sites to read articles seemed to be getting out of hand. I wanted to limit this & came across the pihole dns solution referenced by large numbers of ‘top uses for raspberry pi’ type articles. I had a pi available from some project that never panned out years ago.

BACKGROUND/PREREQUISITES

Many articles exist on the internet on how to go through the process of creating a pihole DNS blocking solution. I thought I would include my own experience that resulted from taking bits of information from a number of sites to get my home network set up. Keep in mind the exact step by step process might be subject to minor changes as time goes on. For this solution obviously you will need a raspberry Pi device, micro SD card (or other storage), & a way to connect the Pi to your home network.

STREAMLINED PROCESS (Windows)

-From https://www.raspberrypi.com/software/ download & install the pi imager (for imaging the piOS to a storage device such as micro SD card/formating the filesystem on storge device).
-Run the imager. Under the operating system option choose erase. Under the storage option choose the storage device you have plugged into your computer. Now click the write button to format the storage device.


-In the imager (still running), under operating system you will now choose an operating system based on the pi you have. For example i was using an old pi3 & needed a 32 bit image so i selected “Raspberry Pi OS (32-bit)”. If you have something else pick the “Raspberry Pi OS (other)” option & you can find 64 bit options. Then pick the storage device under storage option.
-Before you write to the storage device, click the gear box for advanced options. Set image customization options value to always use (makes this process easier if you have to redo), Give the pi a hostname, enable ssh (password authentication), set the username & password, add your wireless network SSID & password, set the timezone. Hit save & then click write.


-Once installation is complete, eject the storage device & put it into a powered off pi. Power up your pi & make sure it is connected to the home network (direct ethernet cable is best).


-You will need to find out the IP of the Pi assuming it wasnt assigned manually. This can be done by logging into your home network router & looking for a MAC addresses that begins with “b8:27:eb” (pi foundation). Personally i use a mobile app such as fing or Net Analyzer to scan the network so i can see everything.
-Once you know the IP you will use a terminal emulator such as putty (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) to launch an ssh session to the pi IP & log in with the username & password you set.


-After logging in type “sudo su”, “passwd”, then enter a password to secure the admin access to the pi.
-type “sudo su”, “curl -sSL https://install.pi-hole.net | bash” to install the pihole software.
-assign the pi static ip addresses on whatever network interface(s) you have. This ip you will want to be static so you can point other devices to it for DNS/Ad filtering functions (example eth0=10.1.1.88).
-go through the prompts & if you have a certain DNS service you want to use add it (i use cloudflare becuase at the time of writing this article it was the fastest (1.1.1.1), then my backup was an openDNS service). While going through the prompt allow http server package installation for a web nterface, allow FTLDNS/log queries & adjust the options to your preference (i did show everything to be able to see if it was working & how well).
-gather the dns server information at end of installation (example “http://pi.hole/admin” or “http://10.1.1.88/admin”), & exit back to the prompt.
-change password for the web interface by typing “sudo pihole -a -p” & entering your password (i kept my three passwords the same which is not the most secure but still a step up from defaults)


-you can exit the terminal session & log into the web interface. Here you will want to go ti the Adlists seection after logging in to add lists of sites that will be blocked by the pi. The best source i know of at this time of lists is https://firebog.net/. From the site pick the blocking lists that most apply to your situation & add then to the pi. I run three (all to target ads).


-Once you are done with adding the lists you the final step in this process is to change the settings on your other devices. For example my mobile phone connects to the wireless network at my house & in the connection settings for the wireless network i would set the dns server ip to 10.1.1.88 so that all dns now goes through this pihole solution i put in place.
-make sure to update after adding lists under the Tools drop down (update gravity).

DOES IT WORK

-this can be tested a number of ways. In my case after i had the pi set up. I found a page where i knew the advertisements would be excessive. I went to the page without the dns change on my phone & took a screenshot. Then i went & changed my dns servers in connection settings on my phone manually to the pi ip i set earlier. I went back to the webpage after clearing cookies. A large number of ads had blank boxes where once a ton of garbage was before. Not everything appeared to be removed but this still limited many of the advertisements that fill needless space in my thoughts.