DEV Community

NAEEM HADIQ
NAEEM HADIQ

Posted on • Originally published at Medium on

Block all Ads with a Pi-Hole

Seeing ads on every site you visit and between the movies you see are being nightmarish in times where you relay on online websites for work as well as leisure.

There are a number of ways to avoid this including browser-based plugins such as Adblock that Blockout ads that appear on your viewport. But these are limited to a particular browser or at instances the specific computer. There are devices like a mobile where even games show up ads that cannot be blocked by this method, which is where a network-wide ad-block comes into the picture.

Pi-Hole is a DNS Sinkhole on a 5$ Pi zero on a network

What is a DNS Sink Hole?

DNS Sinkholes are black holes in the Network that feeds on requests from preidentified blacklisted domains and returns a null address while forwarding the non-blacklisted domain requests.

Setting up a Pi-Hole

  1. Setup a Raspberry Pi

i)Use any Raspberry Pi,

ii)Connect it to power

iii)flash an os to the sd card(such as raspian: https://www.raspberrypi.org/downloads/raspbian/) to it.

This can be done by tools like balena etcher.

iv)Insert the sd card to the pi and power it on

2. If you’re doing a headless install like us (no monitor/keyboard required), you’ll need to enable SSH before booting up the Raspberry Pi

i)Replug your SD card to allow Windows to recognize the new Raspbian partition layout

ii)You should see a partition named boot

iii)Create a file inside the drive “ boot ” folder called “ssh” with no extension

3)Plug your SD card into the Raspberry Pi followed by networking, and then power.

4)Since we did a headless install, we’ll need to search for our raspberry pi's IP address so we can access it over SSH.

This can either be done through the Routers ip listing or by tools like angry ip scanner. Look for the hostname “raspberrypi”.

5)Now that we’ve found our Raspberry Pi’s IP address + MAC Address, we need to assign it an INTERNAL/LOCAL static IP address.

i)This process is going to vary wildly based on which router/DHCP server you use, so we’d recommend Googling your router’s model name/number (can be found on the back) + “how to set static IP” (ex: “Netgear R5000 how to set static ip”).

ii)Log in to the admin page either with the Iogin credentials listed on the back of the router, or by googling the model number of the router along with “default password”. Some routers use a randomly generated default password, so googling will not work for those.

iii)Once logged in, look for a tab labeled “DHCP Reservation”, “Static IP Assignment”, or something along those lines.

iv)either choose the mac address with hostname pi or enter the mac id you gathered with angry IP scanner and assign an IP not used by any other device in ur network.

v)Hit Apply to restart your router.

6)Restart your Raspberry pi to ensure it boots to the new config

7)Access the Raspberry Pi over SSH With any SSH Client tool such as Putty.

Username:pi

Password:raspberry

\*these are the default username and password
Enter fullscreen mode Exit fullscreen mode

8)Now that we’re logged in over SSH, start by changing the default password, and updating the Raspberry Pi.

To change the user password enter the command “passwd” and press enter.

  1. You’ll then be prompted to enter the current password (this is “raspberry” so enter that)
  2. Then enter your desired new password

Once that is done type in

sudo apt update
sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Our Raspberry Pi is now updated, set to a secure password and ready to install Pi-Hole onto!

9)Copy the Pi-Hole install command from their website, paste it into the SSH client,

wget -O basic-install.sh https://install.pi-hole.net
sudo bash basic-install.sh
Enter fullscreen mode Exit fullscreen mode

10)Press Enter until you get to the “Choose An Interface” page. The default “eth0” interface for Ethernet users should be selected by default. Press Enter to continue.

“wlan0” should be selected if you’re using WiFI

“en0” if your using lan

11) On the next screen, select your upstream DNS provider. This is where requests will be forwarded if they’re not blocked by Pi-Hole (ie. if they’re not found in it’s block/black lists). We will be using Google DNS, and if you don’t know what this means, stick with that.

12) The following screen allows you to select which of the default block list’s you’d like to use. We will leave these all on, but you can use your arrow keys and space bar to (de)select any of them as you wish. Press Enter to continue

13)Next up, it will ask you if which IP protocols you want to block ads over, leave this at the default unless you know what you’re doing. Press Enter to continue.

14)The next screen will list the IP address of the Raspberry Pi and the IP of your router, assuming you’ve set a static IP, just click Enter to continue.

  1. If you get a screen about an IP conflict, just ignore it and click Enter to continue

15)You’ll then be asked about the web interface, web server, and logging modes. Leave these all at default by clicking Enter.

16)After all that, Pi-Hole is going to do a bunch of stuff, and it might take a couple minutes so sit back until you’re greeted with an “Installation Complete!” page. This will list the IP and password for the Pi-Hole web interface.

17) Copy the IP into your browser, and log with the listed password. Huzzah! You now have a functioning Pi-Hole installation

18)Setting Up Pi-Hole to Run on Your Devices / Whole Network

To enable Pi-Hole on a device-by-device basis, you’ll need to manually set the DNS IP address in your device settings.

  1. For each of these, substitute the IP in the tutorial for the IP of your Raspberry Pi

iPhone refer to Link

Android Refer to Link

To enable Pi-Hole on a Router level, meaning it will work on all your devices automatically, you’ll need to configure your router’s DHCP server’s default DNS settings.

This process is going to vary wildly based on which router/DHCP server you use, so we’d recommend Googling your router’s model name/number (can be found on the back) + “how to set DNS servers” (ex: “Netgear R7000 how to set DNS servers”).

19) Improving the performance

  1. To enable some common whitelisted false-positives run the command listed here: https://github.com/anudeepND/whitelist
  2. For some great info on the Pi-Hole web interface read the lower portion of this tutorial: https://www.smarthomebeginner.com/pi-hole-tutorial-whole-home-ad-blocking/#Configuring_Your_Router_8211_Whole_Home_Ad_Blocking

Oldest comments (1)

Collapse
 
mccurcio profile image
Matt Curcio • Edited

This is a really nice tutorial. Many people do not have the patience and time to make a step by step tutorial, so THANKS. Looks well thought out too. I am looking forward to trying this one later.

By the way, I couldn't resist...
youtube.com/watch?v=j6nVUbN_DWw