Installing PiHole and blocking ads on a Raspberry Pi

For those of you that are not familiar with PiHole, it is a group of software packages that will block ads from entering any device on your network. It is able to do this by taking over the task of DNS resolution for hostnames and checking them against a "blacklist" and simply denying the request. I wanted to repurpose an ancient Raspberry pi B+ for this project I had sitting around gathering dust but I soon found that the more recent versions of Raspbian were far too large and had too much overhead for my device since it only had a single core and 512MB RAM.

After doing some research into alternatives I decided to give DietPi a shot since it was designed to be very lightweight and seemed ideally suited for the B+. Installing is the same as most other images, I use Linux so the USB Image writer tool that came installed with Mint wrote the image to the 4GB sdcard I had on hand. There are tools for Windows and Mac that will write .img files to disk or sdcard such as Win32 Disk imager and balenaEtcher.

DietPi automatically installs and resizes the partitions to use the maximum available space of the sdcard. Once you login it automatically starts the update procedure, when finished, you are presented with a configuration wizard that begins with submitting survey data.



Dialogs setting passwords for user accounts.








The DietPi has several scripts built in to make installing optimized software packages that are commonly used for specific tasks such as Samba for file Windows sharing, Apache for serving webpages, Torrent clients etc. In that list near the bottom is PiHole.



The functionality depends on the devices querying the PiHole for all DNS requests, there are at least a couple of ways to do this depending on the router you use on your network and whether or not you want all of the devices to block ads, spam, malware sites, porn etc.. If you desire to have it handle every device on the network you will have to configure your router to do one of two things. Either set it to use the PiHole as its DNS server and retain DHCP duties or set it to offload the DHCP function to the PiHole. I hade issues with reliability when the Pihole was set as the DHCP server so I opted to configure the router to continue to supply ip address on the network. What you give up is losing statistical information that the PiHole can generate for each and every unique device on the network. When the router simply forwards requests to the pihole for DNS the PiHole only shows the ip of the router or gateway showing each and every request coming fron one ip address. What you can also do is to statically assign each sevice the Piholes ip address for its DNS server, the process becomes more involved and manual since you are now assigning static ip addresses to each device. On a small network that isn't too much trouble but if you have 20 of more devices its a bit of a headache. I personally was not concerned with having a high degree of granularity as to what host was doing what. I just wanted to stop the ads from coming in.