Introduction: Ad-blocking Using Raspberry Pi

Raspberry Pi blocks annoying Internet ads on all your devices using Pi-hole software.
Pi-hole works by operating as your Domain Name System (DNS). When you enter the domain name into your browser address bar, you contact your trusted DNS and provide them the domain name. In return, the DNS returns to you the IP address for the website you visit and the assets are downloaded and displayed in your computer.

The Pi-hole works as an intermediary step between your router and devices, and the DNS server of your choice. The Pi-hole directs your DNS request to the usual DNS provider if the domain name you are visiting is not in a blacklist. You can also add links to the blacklist yourself.
As such, when our device or router sends a request for data from advertisements sites, rather than forward the request to the DNS, the Pi-hole simply returns an erroneous IP address for the asset such as 0.0.0.0. This means the device or browser gets an error message and the advertisement does not get downloaded.
(Pi hole is free, but powered by donations)

Supplies

1 x Raspberry Pi 3B+
1 x 5V 2A Power Supply
1 x SD Card with Raspberry Pi OS installed
1 x HDMI to HDMI Cable (length to suit your application)
1 x Keyboard and Mouse
1 x LCD TV or Monitor with HDMI Input

Step 1:

Building the prototype is incredibly simple. We have built our project using the Raspberry Pi 3B+ but any of the Raspberry Pi’s will be sufficient with Raspberry Pi OS (Raspbian) running.
Firstly, we need to ensure that all of the OS and associated software is installed and up to date. This can be done by entering following command in terminal (without hash symbol)-
#sudo apt-get update

Step 2:

Enter the following line to start installation process
#sudo curl -sSL https://install.pi-hole.net | sudo bash

A blue screen will prompt you that you are about to transform your Raspberry Pi into a network-wide ad blocker. Press OK to accept.

Step 3:

Now, you will be shown a warning reminding you that the Raspberry Pi will need to be given a static IP address. We will do this later, so press OK for now.

Step 4:

In the next screen, you are asked to select which method of internet connection you will be using.
Eth0 = ethernet connection.
Wlan0 = WiFi connection.
Use arrow keys/spacebar to select your desired option.

Step 5:

You will then be prompted to select which DNS server you wish to use. You can choose any of them. We like to use OpenDNS

Step 6:

You will then be asked which third party black list you want to use. You can also use all of them (if available).

Step 7:

Now, you will be prompted to select which protocols you wish to use. Select both IPv4 and IPv6 and hit OK.

Step 8:

You will then be provided with the IP address, port and gateway for your Adblocker.
You will then be shown a long string of code as shown here. This is the DNS address that we will use for the IPv6 protocol.

Step 9:

You will then be asked if you wish to install the web admin interface, which you do. This interface will allow you to easily change settings on the Pi-hole and add websites to the black or white lists. After hitting OK, you will also be asked if you want to install the web server which you do, so hit OK.

Step 10:

This will bring up another dialog box, asking if you want to log queries. We selected Yes, but note, this creates a list of every website / domain your computer connects to.
If you do decide to log, you are then shown another screen asking what information you wish to log.

Step 11:

Once the install process is complete, another blue screen will appear letting you know the install is complete.
This screen will show your IPv4 and IPv6 DNS server addresses and it will also assign to you a web address for your admin console.

It will also provide you a password for logging in your admin console.
Note down these details on paper before hitting ok. Now, your Raspberry Pi is ready to act as a network wide ad-blocker.

Step 12: SETUP FOR USING AD-BLOCKER ON ANDROID DEVICE-

Connect your phone and Raspberryto Pi to the same wifi network.

Step 13:

Install 'DNS Changer' on your phone from app store.

Step 14:

Run the app and select 'Custom DNS' option. Also tick 'Enable IPv6' checkbox.

Step 15:

Now enter IPv4 and IPv6 addresses you recorded above in their respective fields.

Step 16:

You should also enter OpenDNS IPv4 (208.67.222.222) and IPv6 (2620:119:35::35) server addresses in optional fields. So that your phone remains connected to internet even if Raspberry Pi stops working due to power supply failure.