I recently was fascinated by Raspberry Pi and the maker communities behind it. One of the useful projects you can build with Raspberry Pi is Pi-hole. It blocks ads, tracking and malicious websites on every device on your local Wi-fi network, and have an easily manageable web interface.
What you will need
- Raspberry Pi 4 Model B
- Wi-Fi Router
You can follow the steps on the official website to install Pi-hole on a Raspberry Pi 4 Model B.
On your Pi, clone the Pi-hole repository and run the installation script:
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole cd "Pi-hole/automated install/" sudo bash basic-install.sh
Follow through the installation wizard. This article has some good information about the wizard steps.
Router DNS Configuration
Next, you need to configuring the router's DHCP clients to use Raspberry Pi as their DNS Server so that when the clients resolves IP address of an Ad server Pi-hole would block it. To do that you need a couple of things:
- Raspberry Pi's IP Address
- Access to router's web admin interface. In my case it was
Find Raspberry Pi's IP Address
There are plenty of ways to find your Raspberry Pi's IP address.
Since my Raspberry Pi supports mDNS by the Avahi service,
ping raspberrypi.local and
ping6 raspberrypi.local from my computer return Pi's IP addresses.
If that's not the case for you, you could try out the
nmap method. Run
sudo nmap -sn <your-computer-IP>/24 to scan the devices on your local network and look for the hostname containing Raspberry Pi.
Static IP Address
You'll also want the Raspberry Pi's IP address to be static so that you won't need to reconfigure Pi-hole and your router for example if you restart Raspberry Pi.
To set static IP address on a Raspberry Pi:
Configure Router DNS
Configuring DNS is pretty straightforward: Check the manual of your router brand and go to the router admin page and set DNS override to the IP address of the Raspberry-Pi.
Note that it's recommended to use Pi-hole as the single DNS server (Or servers, if you care about redundancy) because your clients might send blocked requests to secondary DNS Servers.
http://<Your-Pi-IP>/admin to manage Pi-hole.
If the IP Address of the Pi changes, you will need to reconfigure Pi-hole. Opening a terminal from Raspberry Pi and running
pihole -r does the job.
Turn on SSH
Preferences → Raspberry Pi Configuration → Interfaces → Enable SSH then