Pi-Hole
Summary
Introduction
Why do you need a Pi-hole? Well aren’t you just tired of having ads all the time and needing to use an ad-blocker that may or may not be selling your data to organizations? If I could describe to you what a Pi-hole is in two words it would be “better ad-blocker”. Before getting into the details of how to set one up, I will explain how it works.
Okay, this might look really overwhelming but trust me once you setup the Pi-hole, it will all come together. Right now, our network is pretty basic. Any time your computer wants to talk to a website, it has to ask your router first. All we are doing is adding the Pi-hole, so that your computer asks it instead. The router is still needed to connect to the internet (sorry if you thought this was free internet).
Setting Up Pi
All you need is the Pi Zero W, 5V Power supply, and 8GB SD Card
Getting the dev kit is recommended if you want to do other projects on your Pi Zero.
-
The first step is to format the SD card that was included. It may already have files and an OS system included, so it is always good to start with formatting your SD card.
-
Insert the SD card on your computer.
-
If you don’t have the format option on your computer:
- Download the Formatting Tool for Windows.
- Mac Formatter
SD Formatting - Select the location of your SD card.
- Choose Overwrite format and give it a name.
-
-
Now for our Pi, we need to choose a lightweight OS that doesn’t take up too much space, yet it does the job it needs to.
-
I chose DietPi because I don’t need a desktop environment.
-
A tool I use to write disk images is Etcher, you can download it here.
- Unzip DietPi.7z file using 7-zip (for Windows).
Writing Image - Open Etcher and drag the DietPi.img file, then choose the SD card location, and hit FLASH!
- Unzip DietPi.7z file using 7-zip (for Windows).
-
If Etcher ejects your SD card, unplug and replug the SD card.
Configure OS
-
Setup the Pi so that we can
ssh
into it from our computer.- Modify the dietpi.txt file on the SD card.
1 2
AUTO_SETUP_NET_ETHERNET_ENABLED=0 # {Not mandatory to change it to 0} AUTO_SETUP_NET_WIFI_ENABLED=1
- Modify the dietpi-wifi.txt on the SD card if you are using WiFi .
1 2
aWIFI_SSID[0]= 'WIFI_NAME' aWIFI_KEY[0]= 'WIFI_PASSWORD'
- By default
ssh
should be enabled in DietPi.
-
Eject and remove the SD card.
Router Settings
-
Insert the SD card into your Pi and power it up.
-
If you didn’t set a static IP for your Pi, we need to find which IP to connect to.
-
The steps below may vary depending on the router dashboard.
-
Access your router dashboard
{usually 192.168.0.1}
.1
ipconfig | findstr "Default Gateway" # This will show your router IP
-
Click on the
Basic
tab at the top of the page. -
View the
Connected Devices
. -
Your hostname which is DietPi and the IP should be there.
- If it is not, power off your Pi, re-insert your SD card into your computer and look at the WiFi configurations.
-
-
Since you do not want the router to assign a new IP to your Pi all the time, we will set a static IP at the router level.
- On the same page for your router dashboard (Basic tab).
- Click on DHCP Reservation.
- Find the hostame/IP and click on add.
- Now this IP has been reserved solely for Pi connectivity.
Later on, I will explain why we set a static IP at the router level.
Let’s SSH-it
-
SSH into your Pi using MobaXTerm or any command terminal with SSH installed.
-
1 2
ssh root@<Pi_IP> Password: dietpi
-
Now it will automatically look for updates and apply them.
-
Change the root and user passwords as instructed
{make sure to remember them}
. -
You can install and uninstall software as you wish or do it later after everything is updated/upgraded
Install Pi-hole
-
1
curl -sSL https://install.pi-hole.net | bash
Installation of Pi-hole -
Choose your DNS provider – default Google (8.8.8.8). I like Cloudflare as well (1.1.1.1).
-
Ad block lists - Keep it as it is and we will add more if we need to.
-
IP reserve - already configured it so that this IP is static.
1 2 3
Few things to keep in mind: ** What happens when we change our router (eg.new Internet provider)? We will have to set the static IP again and re-configure ** The router has a set block of start IPs and end IPs. By choosing an IP whose last digit is close to 2 or close to 254, there is more of a guarantee that we won't have to keep reserving an IP everytime we switch Internet providers
-
Web Admin Interface - keep the default.
-
Log Queries - default answer.
- Now Pi-hole is setup, but there is one final step that we need to complete for the whole network flow to work.
Router Configuration Again
-
Head over to your router dashboard one last time.
-
Go to the Basic tab.
-
Click the DNS tab and set it to Manual.
-
Add your Pi-hole IP to DNS1.
-
Now your network flow looks like the image below:
Something to keep in mind: The first time a device connects to your WiFi, the router will push down the configurations inlcuding the DNS we set above. Now, when the device makes a DNS request, it will talk directly to the Pi-hole.
- Restart your router
- Everything should be good to go! Visit http://pi.hole and have fun exploring