Although online advertising is a major source of income that can make money for your favorite website (including this one), sometimes people want to block it for various reasons, such as performance or privacy issues. You can install blocking software on every device you own, but the most effective way is to use Pi-hole to create a server to filter all your network traffic at the local network level.
Pi-hole is a network ad blocker based on Raspberry Pi.We install the software to raspberry pie Run Raspberry Pi OS, run a short installation script, and then point our machine to the IP address of Raspberry Pi for instant ad blocking. We can also-and we strongly encourage this-add websites you frequently use (such as tomshardware.com) to the whitelist so that you can help them keep them up and running.
In this tutorial, we will turn a spare Raspberry Pi into an ad blocker, safely hidden in our network.We used a Raspberry Pi 4, But considering the low requirements for the Pi hole, this is a good opportunity to resurrect your old Raspberry Pi hidden in the drawer.
For this project, you need
- Any Raspberry Pi with Ethernet
- Power cord and Ethernet cable for Raspberry Pi
- A Windows computer
Set up your Raspberry Pi
1. Download and install Raspberry Pi Imager From the Raspberry Pi website.
2. Insert a spare microSD card Enter your computer. Please note that this card will be deleted.
3. Start the Raspberry Pi imager And press SHIFT + CTRL + X to open a secret configuration menu.
4. Scroll down and click Enable SSH then Set a new SSH password. Click Save when finished.
5. Under the operating system Select the Raspberry Pi operating system (32-bit).
6. Click the button under Storage and Select microSD card. Before proceeding, please double check that you have the correct drive.
7. Click to write Download and write Raspberry Pi OS to the microSD card. When finished, remove the card from the computer.
8. Insert the Raspberry Pi operating system microSD card Into your Raspberry Pi. Then connect your Raspberry Pi to the network via an Ethernet cable Finally, connect the power supply to start the Raspberry Pi.
Install Pi-hole via SSH
SSH is a secure connection with Raspberry Pi, and is the best way to install and set up Pi-hole. We can connect using an SSH client. For Windows, this is PuTTY, while Mac and Linux users can connect directly through the terminal. Using SSH, we can install software and manage the Raspberry Pi as if we were sitting in front of it.
1. Windows users, download and Install putty. Linux and Mac users can directly open the terminal.
2. Pass putty Enter the hostname as raspberrypi.local (On some networks, this is just raspberrypi without .local) Then click Open.
3. Enter your username and password When prompted. Please note that for security purposes, these will not be printed to the screen.
4. Update your software repository Then download the latest update for Raspberry Pi.
$ sudo apt update $ sudo apt upgrade -y
5. Install Pi hole Use this line to install the script. This command will download the script and then run the installer in the terminal.
$ curl -sSL https://install.pi-hole.net | bash
6. The Pi-hole installer will start by updating the available software, and then the menu-based installation wizard will start. Press Enter To install.
7. Select eth0 as the interface Use with Pi hole. Press Tab to move the red highlight to Ok, then press Enter. This is our Gigabit Ethernet port, which will provide the best connection.
8. Choose your upstream DNS provider. We chose Google, but there are many other options. Press Tab, and then press Enter.
9. Accept the default list of blocked sites By pressing the Tab key and typing.
10. Accept the default IPv4 and IPv6 protocols By pressing the Tab key and typing.
11. Accept the current network settings and set them to static. Please write down the details as we will need them later.
12. Install web management interface By pressing the Tab key and typing.
13. Install lightppd web server Used to provide Web management pages by pressing Tab and Enter.
14. Accept the default log Options.
15. Accept the default privacy mode By pressing the Tab key and typing.
After the installation is complete, the last page summarizes the IP address of the Pi-hole device and provides the login password for the management webpage.
16. Change the network administrator password in the terminal Use the following command. You will be prompted to enter the password twice.
$ pihole -a -p
Set up network connection for Pi-hole
With our Raspberry Pi running Pi-hole set up and running, we now need to point our device to it so that Pi-hole’s DNS server can block unwanted advertisements. Here we manually set up the wired network connection with Windows 10. The steps for Wi-Fi are similar.
1. Right-click on the Windows logo and select Network Connection.
2. Click Properties.
3. Click Edit to update the network configuration.
4. Edit your IP address To the address you want. We choose to stick to the content published by the router’s DHCP server. Set the subnet prefix length to 24. The gateway is the IP address of the router, which is 192.168.0.1 in our example. The preferred DNS is our Pi-hole DNS server, 192.168.0.24. If our Pi-hole device is offline, the alternate DNS is used, in this case, it is Google’s DNS server. Click Save to write the changes and restart the network interface.
How to whitelist a site in Pi-Hole
Considering that a large part of the revenue of many content websites (including our website) rely on advertising, it makes sense to whitelist the websites you wish to support so that they can provide you with advertisements. Pi-hole has a whitelist menu where we can add specific domains and subdomains, and these domains and subdomains will be added to Pi-hole’s list.
1. Open a web browser to access the IP address Your Raspberry Pi, then type /administrative. For our setup, we went to http://192.168.0.34/admin/
2. Log in to your Pi-Hole By entering the username and password. We previously changed the administrator login password.
3. From the dashboard Click whitelist.
4. Under the domain, Add the URL of the site you wish to whitelist, Then Click add to whitelist. The site will now be able to provide advertising services.
By clicking the button under status, you can enable/disable domains in the whitelist. Click the trash can icon to delete the whitelisted domain.
5. Click to log out Return to the default management page.
With it, your browser tabs have no ads, and your browsing speed is much faster, all thanks to the spare Raspberry Pi hidden in the drawer.