Skip to content

Instantly share code, notes, and snippets.

@abmmhasan
Last active October 25, 2023 12:48
Show Gist options
  • Save abmmhasan/2398b19c9513e372185a7cc68dbe4fcb to your computer and use it in GitHub Desktop.
Save abmmhasan/2398b19c9513e372185a7cc68dbe4fcb to your computer and use it in GitHub Desktop.
Setting up your own Ad-blocking DNS server is easy with Pi-Hole! It also gives you full control as it, itself act as a DNS server(obviously with help of your chosen Global DNS providers).

1. Buy a Raspberry Pi (or any low-cost PC build)

At first buy a Raspberry Pi (I recommend Zero edition for minimum cost) with casing (official one is enough for Zero). My configuration:

  • Rapberry Pi Zero with Official Casing (used the Cover with Center Hole)
  • MicroSD card
  • Micro-USB to LAN converter (can be replaced with OTG Cable + USB to LAN converter)
  • Micro-USB power cable
  • LAN connection cable

2. Prepare OS

Download Raspberry Pi Image from official site. Follow instruction for OS specific installation. Afterward write the Raspberry Pi Lite Edition (recommended but you can also use other editions as well) to your MicroSD card. Before clicking on Write check the details by clicking on Gear icon and modify as required (hostname, timezone, user credentials, ...).

3. Put it all together

After writing is complete and safe ejection, insert the card in Pi put them in casing connect all the cables (the casing even on the board have indication, which port is for what). Plug into power and connect with Router LAN port.

4. Prepare your Router

If your router don't use DHCP you can omit this section!

As our router provides IP through DHCP, we need to specify an IP for our Pi module. Set up your router to provide Static IP (by searching the Module through Router's client interface)

5. Configure the OS

Login via SSH to your Pi module.

  • You should look into primary configurations of your Pi OS. Type in sudo raspi-config. Go through the menu & check (& change if required) the configurations.
  • Up next, type in sudo nano /etc/dhcpcd.conf. Change following lines (you can find near the end of file)
interface eth0
static ip_address=[IP address with subnet mask, This is static standalone IP for the Pi Module]
static routers=[router gateway address]
static domain_name_servers=[router DNS or other preferred DNS server]

Save the file (CTRL + O) and Reboot (sudo reboot).

6. Install Pi-hole

Install Pi-hole using following command:

sudo curl -sSL https://install.pi-hole.net | bash

Afterwards, you will go through several options, select options as you need (obviously must install all the modules of Pi-hole specially Web GUI). Once installation is complete you'll get the credentials (password) for dashboard login.

7. Finalize

  • Now login to your Pi-hole dashboard using <assigned_IP>/admin. Go through dashboard options, check all and tweak as you need.
  • Don't forget to check the DNS servers.
  • Login to your router and change the DNS server to your Pi module IP.

And You are ready!!!

  • Youtube and some site may still show Ads (as these links are adaptive) but you can manually block them by tracking the URL and blocking via Web interface.
  • Update Gravity atleast every month to keep your tracking DB updated!

CLI commands

  • Change password: pihole -a -p
  • Update Pi-Hole: sudo pihole -up

Blocklist

Useful links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment