An Ambassador Moment: Raspberry Pi DNS Server AdBlocker
2021-12-10 | By Har Patel
License: See Original Project
Open any website today from news sources to entertainment sources, they each have something on them that is common, yep that's right Advertisements!!! Ads to the left of the webpage, ads to the right of the webpage, in the center, everywhere. Ads are one of the most annoying things today, showing up virtually everywhere as they are a great source of revenue. I got to a website today and it is so annoying because of all the ads, which also make browsing through the website very difficult.
There are various solutions available today. For your computer, ads can be blocked by using browser extensions on your local browser. For your phone, using a browser that blocks ads is the way. However, this only prevents ads being blocked on the browser that has the extension installed or if the right browser is installed. If any other apps are used on your laptop or phone, the ads just show up. Every phone has its own app, every browser its own plug-in, and they increasingly don’t work. There have been many times where the ad blocker software has had to be turned off to access a site. Recently, I have been getting very frustrated with having to turn my ad blocker off and back on. I started looking at ways to create my own ad-blocker.
You could install blocking software on each device you own like before, but due to its limitations the most efficient way is to create a server using Pi-hole. Pi-hole(“pie-hole”) blocks all ads at the local network level. It’s like a firewall just for advertisements, it makes the internet better and easier to use, and it’s cheap and easy to build. Pi-hole lets you block everything at the network level and it works for every single device on that network.
In order to build your very own pi-hole, all you will need is a Raspberry Pi and a micro SD card for the software to run on the Pi. What makes this even more elite is that you can run this project on a Raspberry Pi Zero W, as it has internet capabilities and not much storage or processing power is required.
These two things are all we need hardware wise! The rest is in the software and soon we will have our wonderful ad blocker. To install the software, follow steps:
1. Download and install Raspberry Pi Imager from the Raspberry Pi website.
2. Insert a spare microSD card into your computer. Note that this card will be erased.
3. Launch Raspberry Pi Imager and press SHIFT + CTRL + X to open a secret configuration menu.
4. Scroll down and click on Enable SSH and then set a new SSH password. Click Save when done.
5. Under Operating System select Raspberry Pi OS (other).
6. Then select Raspberry Pi OS Lite (32 bit).
We want to use the lite version with SSH enabled so that it takes up less space and less processing power. The lite version still has the Raspian OS, just not the full desktop version.
7. Under Storage click on the button and select the microSD card. Double check that you have the right drive before proceeding.
8. Click on Write to download and write Raspberry Pi OS to the microSD card.
After this is installed a few extra steps must be taken to add to the microSD card since we are using the Lite version and the WiFi(802.11) feature of the Pi Zero. So, we need to manually add the WiFi information to the Pi. To this add the following file: wpa_supplicant.conf to the /boot folder of the microSD Card. The file looks like this:
Follow the comments, by placing the wifi network name and password where noted. Continue to set up:
9. Insert the Raspberry Pi OS microSD card into your Raspberry Pi.
10. Find the IP Address of the Raspberry Pi.
a. Log into your router and get this info.
b. Windows: Open Command Prompt and run: `ipconfig/all` and look for the Raspberry Pi.
c. Mac: Open Terminal and run: `ifconfig`.
11. Start an SSH connection to the Raspberry Pi .
a.Windows: download and install PuTTY.
b. Mac: open a terminal and enter username (default: pi) with IP address
i. pi@IP_ADDRESS_HERE
12. Enter password when prompted.
13. Install Pi-hole using this one-line installation script:
curl -sSL https://install.pi-hole.net | bash
This command will download the script and then run the installer in the terminal and a menu-based installation wizard will start.
14. Accept all default settings in the installation wizard or as recommended.
15. Once installed a window will open with the web address of the Pi-hole dashboard.
This displays all the quieres blocked and not blocked as well as the amount of domainsThe final thing left is to add the DNS server to devices. I chose the route of adding individual devices as I live with 5 other roommates, so I made it so the whole router is not using the DNS server.
16. Go to WiFi settings and then hit network preferences.
17. Click Advanced, then DNS, hit the small plus button and add the custom IP address of the Pi-hole.
WE DID IT! We have our very own working ad-blocker. Below are before and after screenshots of popular websites with ads.
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum