While there are plenty of ad-blockers that can banish adverts from your laptop or computer, these rarely work on other devices, such as smartphones and tablets. This article will show you how to transform your Raspberry Pi into a network-wide ad blocker, using Pi-Hole. Once completed, you’ll be able to block ads across your laptop, computer, smartphone, tablet, and any other device that’s connected to your network.
Note: to get started, you can check out this article on what Pi-Hole is and how it is useful.
What you’ll need
To complete this tutorial, you’ll need:
- Raspberry Pi that’s running Raspbian. If you don’t already have Raspbian installed, grab the latest version and flash it using Etcher.
- Power cable that’s compatible with your Raspberry Pi
- External keyboard and a way to attach it to your Raspberry Pi
- HDMI or micro HDMI cable, depending on your model of Raspberry Pi
- External monitor
- Ethernet cable or Wi-Fi connection
Once you’ve assembled your tools, you’re ready to create your network-wide ad-blocker.
Installing Pi-Hole on your Raspberry Pi
If you haven’t already, attach your external keyboard, monitor and any other peripherals to your Raspberry Pi, then attach the Pi to a power source.
As soon as your Raspberry Pi boots, you’re ready to download Pi-hole’s installation script. Simply launch the Terminal (by clicking the Terminal icon in the Raspbian toolbar), then type the following command into the Terminal window:
Press Enter. Raspbian will download the script and begin the process of configuring your device to use Pi-Hole.
After a few moments, Pi-Hole’s setup screen should launch automatically.
Keep pressing Enter to progress through the introductory screens until you’re asked whether Pi-Hole should operate over Wi-Fi (wlan0) or Ethernet (eth0).
Use the arrow keys to select either wlan0 or eth0 (this tutorial is using Wi-Fi) and press Enter.
Google, Cloudflare, OpenDNS: choosing a DNS provider
You’ll need to choose an upstream DNS provider, which will be responsible for answering queries for non-ad domains.
Pi-Hole supports the following preset DNS providers, but you can enter your own by selecting “custom.”
- Google (ECS)
- OpenDNS (ECS)
- Quad9 (filtered, DNSSEC)
- Quad9 (unfiltered, DNSSEX)
- Quad9 (filtered + ECS)
This tutorial is using Google, but you can choose whichever DNS provider you prefer.
Which blacklists should Pi-Hole use?
Specify the lists that Pi-Hole should use in order to identify and block undesirable content.
Unless you have a specific reason to change these settings, it’s typically 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 adverts as possible, you should leave both IPv4 and IPv6 selected.
Configuring a static IP address
Use your current network settings as Pi-Hole’s static address. Assuming you’re happy with the information that’s displayed onscreen, use the arrow keys to select “Yes” and then press Enter.
Read the disclaimer carefully, and if you’re agree, select “OK.”
Monitoring Pi-Hole with the web admin interface
You’ll be asked whether you want to install Pi-Hole’s web admin interface. This interface provides an insight into how Pi-Hole is operating on your network, so it’s recommended that you opt to install the web interface when prompted.
If you install the web admin interface, you should also install the “lighttpd web server” when prompted.
Logging Pi-Hole’s data
You can choose to disable Pi-Hole’s logging capabilities, but I recommend leaving these enabled, as they provide some useful information.
You’ll be prompted to select a privacy mode for FTL, which is the level of information that’ll be included in your Pi-Hole statistics. Choose from the following:
- Show everything.
- 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 details except the most anonymous statistics.
- Disabled statistics. Disables all statistics processing, including query counters.
Logging into your Pi-Hole account
The setup dialogue will display the address of Pi-Hole’s web admin interface and the password you’ll need to log into this interface. Make a note of this information!
If you head over to the URL provided, you’ll encounter Pi-Hole’s standard web interface and can log in using your password.
The web admin interface is divided into the following sections:
- Query log. This displays the most recent queries that have been made to the DNS server.
- Whitelist. You can specify the domains that Pi-Hole should never block.
- Blacklist. Are some ads still managing to slip past Pi-Hole? If you can identify the domain that’s responsible for these rogue ads, then you can manually add it to Pi-Hole’s blacklist.
- Disable. This is where you can temporarily, or permanently, disable Pi-Hole so you can start seeing all of your favorite ads again!
- Update lists. Make sure you have the very latest version of Pi-Hole’s ad-block lists by manually triggering an update.
- Query adlists. Use this tool to check whether a particular URL is included in Pi-Hole’s ad-blocking lists.
- Tail pihole.log. This tool lets you 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 Pi-Hole’s configuration, including which upstream DNS provider you want to use.
This is just a brief overview of Pi-Hole’s web admin interface. It’s well worth taking the time to explore this interface in more detail!
Troubleshooting: could not resolve host
While configuring Pi-Hole, it’s possible you may encounter the following error in the Terminal window:
“Could not resolve host
FTL Engine not installed.”
If you encounter this message, run the following Terminal command:
This launches the resolv.conf file in the Nano editor. You’ll need to add the IP address(es) of your chosen DNS provider to the resolv.conf file. For example, this tutorial is using Google as the DNS provider, so a quick Google search reveals that “22.214.171.124” should be added to resolv.conf:
To save your changes, use the Ctrl + O keyboard shortcut, then press Y when prompted.
Close resolv.conf by using the Ctrl + X keyboard shortcut.
Relaunch Pi-Hole’s setup dialogue by running the following Terminal command:
You should now be able to complete the setup dialogue without any errors.
Update your router: Creating a network-wide ad-blocker
You’re ready to update your devices or router to use Pi-Hole. If you want to block adverts across all the devices that are connected to your network, you’ll need to change the router’s DNS settings to point at your Raspberry Pi device.
The process of changing your router’s DNS settings will vary depending on your exact model of router, but as an overview, you’ll need to:
- Head over to your router’s admin 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 the IP address of your Raspberry Pi. If you don’t know the address, you can retrieve it by opening Raspbian’s Terminal window and running the following command:
For instructions on how to update 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 the DNS settings for specific devices and operating systems.
To update your DNS settings on Windows:
- Launch the “Control Panel.”
- Navigate 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 “Networking” tab.
- Select “TCP/IPv4” or “TCP/IPv6.”
- Navigate to “Properties -> Advanced -> DNS” and 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 set up to use your Pi-Hole ad-blocker.
If you’re a Linux fan, you’ll need to:
- Navigate 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 your Raspberry Pi’s IP address.
- Save your changes by clicking “Apply.”
Alternatively, you can update your DNS settings by opening the “/etc/resolv.conf” file.
To update your DNS settings in macOS:
- Select the “Apple” logo in your Mac’s toolbar.
- Navigate to “System Preferences -> Network.”
- Select the connection you want to edit.
- Click “Advanced … “
- Select the “DNS” tab.
- Click the little “+” icon and enter your Raspberry Pi’s IP address.
- Save your changes by clicking “Apply -> OK.”
Pi-Hole will check all your requests against its blacklist and block as many adverts as possible.
If you own an iPhone or iPad, then:
- Launch the “Settings” application.
- Select “Wi-Fi” and tape your home network in the list.
- Select the “DNS” field.
- Delete all current DNS servers and replace them with the IP address of your Raspberry Pi.
To block adverts on Android:
- Launch the “Settings” application.
- Select “Wi-Fi.”
- Long-press on the Wi-Fi network you want to update.
- Select “Modify network -> Advanced options.”
- Tap “DHCP” and then select “Static.”
- In “DNS 1,” enter your Raspberry Pi’s IP address.
- Tap “Save.”