Family Best Time >> Electronics

Turn your Raspberry Pi into an ad blocker

Although there are many ad blockers that can banish ads from your laptop or computer, they rarely work on other devices, such as smartphones and tablets. This article will show you how to turn your Raspberry Pi into a network-wide ad blocker, using Pi-Hole. Once done, you will be able to block ads on your laptop, computer, smartphone, tablet, and any other device connected to your network.

ContentsWhat You'll NeedInstall Pi-Hole on Your Raspberry PiGoogle, Cloudflare, OpenDNS:Choosing a DNS ProviderWhich Blacklists Should Pi-Hole Use?Internet Protocols:IPv4 or IPv6 (or Both)?Set Up a Static IP Monitoring Pi -Hole with web admin interfaceSaving Pi-Hole dataSigning in to your Pi-Hole accountTroubleshooting:Unable to resolve hostUpdate your router:Create a network-wide ad blockerHow to block online ads on specific devices1. Windows2. Linux3. macOS4. iPhone5. android

Note :to start, you can consult this article on what is Pi-Hole and its usefulness.

What you'll need

To complete this tutorial you will need:

  • Raspberry Pi which runs Raspbian. If you don't already have Raspbian installed, get the latest version and flash it using Graveur.
  • Power cable compatible with your Raspberry Pi
  • External keyboard and way to attach it to your Raspberry Pi
  • HDMI or micro HDMI cable, depending on your Raspberry Pi model
  • External monitor
  • Ethernet cable or Wi-Fi connection

Once you've assembled your tools, you're ready to build your network-wide ad blocker.

Install Pi-Hole on your Raspberry Pi

If you haven't already, connect your external keyboard, monitor, and other peripherals to your Raspberry Pi, then connect the Pi to a power source.

As soon as your Raspberry Pi boots up, you're ready to download the Pi-hole install script. Simply launch the Terminal (by clicking on the Terminal icon in the Raspbian toolbar), then type the following command in the Terminal window:

curl -sSL https://install.pi-hole.net | bash

Press Enter. Raspbian will download the script and begin the process of setting up your device to use Pi-Hole.

After a few moments, the Pi-Hole configuration screen should launch automatically.

Turn your Raspberry Pi into an ad blocker

Use the arrow keys to select wlan0 or eth0 (this tutorial uses Wi-Fi) and press enter.

Google, Cloudflare, OpenDNS:choose a DNS provider

You will need to choose an upstream DNS provider, which will be responsible for answering queries for non-advertising domains.

Turn your Raspberry Pi into an ad blocker

Pi-Hole supports the following predefined DNS providers, but you can enter your own by selecting "custom".

  • Google (ECS)
  • OpenDNS (ECS)
  • Level 3
  • Comodo
  • DNS.WATCH
  • Quad9 (filtered, DNSSEC)
  • Quad9 (unfiltered, DNSSEX)
  • Quad9 (filtered + ECS)
  • Cloudflare

This tutorial uses Google, but you can choose any DNS provider you prefer.

Which blacklists should Pi-Hole use?

Specify which lists Pi-Hole should use to identify and block unwanted content.

Turn your Raspberry Pi into an ad blocker

Unless you have a specific reason to change these settings, it's generally a good idea to stick with the defaults.

Internet protocols:IPv4 or IPv6 (or both)?

It doesn't matter if you choose IPv4 or IPv6, but if you want to block as many ads as possible, you should leave both IPv4 and IPv6 selected.

Configure a static IP address

Use your current network settings as the static address of Pi-Hole. Assuming you are happy with the information displayed on the screen, use the arrow keys to select "Yes", then press Enter.

Read the disclaimer carefully and if you agree, select "OK".

Monitoring of Pi-Hole with the web administration interface

You will be asked if you want to install the Pi-Hole web admin interface. This interface provides an overview of how Pi-Hole works on your network, so it is recommended that you opt to install the web interface when prompted.

Turn your Raspberry Pi into an ad blocker

If you are installing the web admin interface, you must also install "lighttpd web server" when prompted.

Pi-Hole Data Logging

You can choose to disable Pi-Hole's logging capabilities, but I recommend leaving them enabled, as they provide useful information.

You will be prompted to select a privacy mode for FTL, which is the level of information that will be included in your Pi-Hole statistics. Choose from the following:

Turn your Raspberry Pi into an ad blocker
  • Show all .
  • Hide domains . Show and store all domains as hidden.
  • Hide domains and clients . Show and store all domains as hidden and clients as 0.0.0.0.
  • Anonymous mode . Hide all but the most anonymous statistics.
  • Statistics disabled . Disables all statistical processing, including request counters.

Login to your Pi-Hole account

The configuration dialog will show the address of the Pi-Hole web administration interface and the password you will need to log in to this interface. Write down this information!

If you go to the URL provided, you will encounter the standard Pi-Hole web interface and can log in using your password.

Turn your Raspberry Pi into an ad blocker

The web administration interface is divided into the following sections:

  • Request Log . This displays the most recent queries that have been made to the DNS server.
  • Whitelist . You can specify domains that Pi-Hole should never block.
  • Blacklist . Do some ads still manage to get past Pi-Hole? If you can identify the domain responsible for these malicious advertisements, you can manually add it to the Pi-Hole blacklist.
  • Disable . This is where you can temporarily or permanently disable Pi-Hole so you can start seeing all your favorite ads again!
  • Update Lists . Make sure you have the latest version of Pi-Hole's ad blocking lists by manually triggering an update.
  • Query announcement lists . Use this tool to check if a particular URL is included in Pi-Hole's ad blocking lists.
  • pihole.log tail . This tool allows you to examine Pi-Hole's log file so you can see exactly how Pi-Hole is processing incoming requests.
  • Settings . You can make a number of changes to the Pi-Hole configuration, including which upstream DNS provider you want to use.

This is just a brief overview of the Pi-Hole web admin interface. It is worth taking the time to explore this interface in more detail!

Troubleshooting:Unable to resolve host

While configuring Pi-Hole, you may encounter the following error in the Terminal window:

"Failed to resolve host
FTL engine not installed
. "

If you encounter this message, run the following Terminal command:

sudo nano /etc/resolv.conf

This launches the resolv.conf file in the Nano editor. You will need to add the IP address(es) of your chosen DNS provider to the resolv.conf file. For example, this tutorial uses Google as the DNS provider, so a quick Google search reveals that "8.8.8.8" should be added to resolv.conf:

nameserver 8.8.8.8

To save your changes, use the Ctrl + O keyboard shortcut, then press Yes when prompted.

Turn your Raspberry Pi into an ad blocker

Close resolv.conf using the Ctrl + X keyboard shortcut.

Launch the Pi-Hole configuration dialog again by running the following Terminal command:

curl -sSL https://install.pi-hole.net | bash

You should now be able to complete the configuration dialog without any errors.

Update your router:create a network-wide ad-blocker network scale

You are ready to update your devices or router to use Pi-Hole. If you want to block ads on all devices connected to your network, you will need to change the router's DNS settings to point to your Raspberry Pi device.

The process for changing your router's DNS settings will vary depending on your exact router model, but as an overview, you will need to:

  • Go to your router's administration page.
  • Log in using your username and password. If you don't know this information, chances are you're using the manufacturer's default username and password. Find this information on the manufacturer's website or in the documentation that came with your router.
  • Look for any tab, menu, or section that contains the words "DNS server" or "DHCP server". Note that these settings may be hidden in an "Advanced Setup" section.
  • Update your router's primary DNS server to your Raspberry Pi's IP address. If you don't know the address, you can retrieve it by opening the Raspbian Terminal window and running the following command:hostname -I

For instructions on updating the DNS settings for your specific router, check the manufacturer's website or the physical documentation that came with your router.

How to block online-ads on specific devices

You can also change DNS settings for specific devices and operating systems.

1. Windows

To update your DNS settings on Windows:

  • Launch the "Control Panel".
  • Go to "Network and Internet -> Network and Sharing Center -> Change adapter settings".
  • Select the connection you want to configure.
  • Right-click "Local Area Connection -> Properties".
  • Select the "Network" tab.
  • Select "TCP/IPv4" or "TCP/IPv6".
  • Go to "Properties -> Advanced -> DNS", then click "OK".
  • Select "Use the following DNS server addresses".
  • Replace the addresses in this section with the IP address of your Raspberry Pi.

Your Windows PC is now configured to use your Pi-Hole ad blocker.

2. Linux

If you are a Linux fan, you will need to:

  • Go to "System -> Preferences -> Network Connections".
  • Select the connection you want to configure, then click "Edit".
  • Select either the "IPv4 Settings" or "IPv6 Settings" tab.
  • In the "DNS Servers" field, enter the IP address of your Raspberry Pi.
  • Save your changes by clicking "Apply".

Alternatively, you can update your DNS settings by opening the "/etc/resolv.conf" file.

3. macOS

To update your DNS settings in macOS:

  • Select the "Apple" logo from your Mac's toolbar.
  • Go to "System Preferences -> Network".
  • Select the connection you want to edit.
Turn your Raspberry Pi into an ad blocker
  • Click "Advanced..."
  • Select the "DNS" tab.
Turn your Raspberry Pi into an ad blocker
  • Click on the small "+" icon and enter the IP address of your Raspberry Pi.
  • Save your changes by clicking "Apply -> OK".

Pi-Hole will check all your requests against its blacklist and block as many ads as possible.

4. iPhone

If you have an iPhone or iPad, then:

  • Launch the "Settings" app.
  • Select "Wi-Fi" and save your home network in the list.
  • Select the "DNS" field.
  • Remove all current DNS servers and replace them with your Raspberry Pi's IP address.

5. Android

To block ads on Android:

  • Launch the "Settings" app.
  • Select "Wi-Fi".
  • Long press the Wi-Fi network you want to update.
  • Select "Edit Network -> Advanced Options".
  • Press "DHCP", then select "Static".
  • In "DNS 1", enter the IP address of your Raspberry Pi.
  • Press "Save".

While using your Raspberry Pi as an ad blocker, it can also be used as a Wi-Fi hotspot or personal web server. Check them out.