Shut your Pi-Hole! (Build your own Network-wide Ad Blocker)
Introduction
Sure it’s easy to install an ad blocker in your favorite browser, but say you want to block ads on ALL your devices – phone, kid’s computer, even your living room Chromecast? You’ll need to set up “Pi-hole”! This Raspberry Pi add-on attaches to your home router and can block ads, including in-game ads, across any device connected to your network. So what are you waiting for? Grab your Pi and let’s get “blocking”.
Caution to Pi-lovers and Ad-haters
Many sites require that you whitelist their domains and will refuse service if you have an ad blocker. Uh-oh. That being said, you can whitelist your favorite sites once everything is set up. However, if any site calls you out for denying them ad revenue don’t say we didn’t warn you.
What You’ll Need
- Raspberry Pi (Model 2 or later)
- SD Card (8GB minimum)
- Power Supply (for your Raspberry Pi)
- HDMI Cable
- Ethernet Cable (CAT5 or CAT6 cable are fastest)
- Keyboard and mouse (for initial setup)
- Access to the Internet
- An open mind for molding
Step One: Download and Flash Raspbian Lite
Most of you have probably flashed images to your Raspberry Pi before, however, for this project we are going to need an OS that is much lighter and faster than ones that you’ve previously used. The latest edition of Raspbian Lite will serve us perfectly. The benefits of this OS over other flavors of Linux (Damn Small Linux, Debian Light, DietPi) is that is has been engineered by the Raspberry Pi Foundation and is extremely easy to flash to a microSD card.
1. Download Raspbian Lite
- The image can be found at https://www.raspberrypi.org/downloads/raspbian/ under the title “RASPBIAN STRETCH LITE”.
- Unzip the file and place in a folder you can remember.
- Plug in your microSD.
2. Download and Install Etcher
- Download the file directly from https://etcher.io/ and install it.
| Etcher Download |
3. Flash the image using Etcher
- Follow the three step process in Etcher to flash your OS to the SD card.
- This can take up to 15 minutes despite the file being less than 100MB.
Flashing an image
|
4. Plug your new OS into the Raspberry Pi
- Make sure you have your keyboard, mouse, network cable, and monitor plugged into the Pi so that you can see the OS boot.
WARNING: The first time you power on your machine it will reboot a number of times. Do not disconnect it from power! This is normal. Just let it run until you see a login screen.
- Follow the on-screen instruction to set up your Pi.
- It should ask for your user name, password, host name, etc. Fill in what you want. After the Pi is configured with Pi-Hole you shouldn’t have to access your OS anymore.
Step Two: Set Up a Static IP Address
Your home router will redirect all devices to your Raspberry Pi, which will act as a mini DNS server. This means your Pi will block any request made to domains that are known to push out advertisements. In order to set this up we will need to make sure that the router always knows where to look in order to find the Pi.
1. Edit the dhcpcd.conf file
- In your Raspberry Pi’s terminal application, type:
sudo nano /etc/dhcpcd.conf
- Scroll all the way to the bottom of the newly opened file.
| dhcpcd.conf |
2. Add a static IP address
- While in the dhcpcd.conf file add the following line of code:
interface eth0
static ip_address=192.168.0.10/24
- This tells the Pi to always use the same IP address when working over ethernet.
NOTE: You may enter in any 192.168.x.xx address you want, but make sure that you can remember it.
3. Save the file but DO NOT REBOOT
- We have just set a Static IP address and you will lose network connection if you reboot.
Step Three: Install Pi-Hole
The Pi-Hole application will consume about 95% of your Pi’s resources once it is installed. This is because you will be redirecting all network traffic to this Pi. This next step will show how you can use as much CPU and RAM as possible for best performance.
1. Run the following commands in your terminal:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install curl
sudo apt-get update
Note: Pi-Hole is not yet installed but these have helped prep the machine for the final installation.
2. Install Pi-Hole by typing:
sudo curl -sSL https://install.pi-hole.net | bash
- The "curl" call will grab Pi-Hole from the URL and the "| bash" command will show some feedback so you know everything is working. For a full documentation on how Pi-Hole installs check out https://pi-hole.net/ or watch the following video:
- If the installation fails for any reason, you can check the documentation at https://github.com/pi-hole/pi-hole/#one-step-automated-install.
Pi-Hole installation screen
Step Four: Point Your Router to Your Raspberry Pi as the Local DNS Server
In order for our Pi-Hole to actually work, we will need to redirect all network traffic to it by setting it as the local DNS. Many routers, especially “home network” style ones, do not allow you to change this but it is worth a Google to see if it is possible on yours. Sadly, because of the breadth and sheer number of routers out there, we will leave you to figure that part out.
Note: If you ARE able to do this on your router make sure you adjust the setting under your "LAN" and "WAN". For a full breakdown on why this is please visit https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245.
- If your router is incapable of DNS requests then you can change which server your individual devices look to. Below are a few examples of common devices.
"Windows"
- Right-click the Start Button and select Network Connections.
- Select your Wi-Fi or Ethernet network.
- Double-click Internet Protocol Version 4.
- Click "Use the following DNS server addresses".
- Under the Preferred DNS server, enter your Raspberry Pi’s IP address you gathered in step three.
"Mac OS X"
- Open System Preferences.
- Click on Network.
- Select your Wi-Fi or Ethernet network.
- Click on Advanced.
- Click the DNS tab.
- Click the plus sign and enter your Raspberry Pi’s IP address you gathered in step three.
"Andoird"
- Open Settings.
- Select Wi-Fi.
- Long press on your current network and select Modify Network.
- Tap Show Advanced Options.
- Change the IP Settings to Static.
- Enter your Raspberry Pi’s IP address under the DNS field.
"iOS"
- Open Settings.
- Select Wi-Fi and tap your home network.
- Tap DNS and enter your Raspberry Pi’s IP address.
You can now navigate to the Raspberry Pi's IP address, in a web browser, to get a larger breakdown of the Pi-Hole's activity.
| Pi-Hole Analytics Page |
Step Five: Whitelist Your Favorite Sites
Pi-Hole blocks a lot of sites; however, there will be times when you will want to whitelist a site. As of right now, it is a little complicated but we will help you walk through it.
1. On your Rasberry Pi enter the following commands in your terminal:
cd /etc/pihole/
sudo gedit whitelist.txt
- From here you can enter the sites you want to whitelist leaving a line break between each site.
2. Restart Raspberry Pi and the changes will take effect.
Conclusion
If all goes well you should have a working ad blocker on your network. If you have any additional questions or concerns please feel free to comment or check out the resources below.
Just thought I would say 'pi'! Haha Puns
ReplyDeleteThat's so punny, I thought I might pi...
DeleteThe step-by-step is great--thanks, Nate.
ReplyDelete