Custom PiHole adlists

Why would I want a custom blocklist?

Recently I’ve found myself having to add multiple whitelist for members in my family. It’s a pain to maintain, so I decided it was time to create a custom blocklist management system. I also have a Gitea instance running and Ive noticed that other adlists come from Github served as static files. Why can’t i do the same? Don’t worry if you don’t have Gitea, this also works with Github.

So, what I can do now is maintain a whitelist and a custom blacklist for members in my family. So all I need to do is to push changes to Gitea and when Gravity is next run then those changes will be reflected in my PiHole servers and my family can click on their ads.

The guide

Step 1: Install and Set Up a Public Repository

First we need a public repository on either Gitea or Github.

It needs to be something which your pihole can access. So if youre unsure, log into your Pihole server and try and ping your Github instance. I won’t go in to how to set up Gitea.

If you need to use Github instead, you just need to create a public repository.

Step 2: Initialize Your Pi-Hole Blocklist Repository

  1. Check out your repository git clone <whateverserver> <your-repo>

  2. Create your folder structure - I’ve seperated mine by family members so each member can have their own blocklist. So in the root folder I have one for myself and another folder for my wife. Inside each family folder I have a blocklist.txt and a whitelist.txt. These files will contain the blocklist and whitelist respectively.

# Family Folder Structure
/home/pihole-blocks/
├── miles/
│   ├── blocklist.txt
│   └── whitelist.txt
├── wife/
│   ├── blocklist.txt
│   └── whitelist.txt
└── shared-lists/
    ├── blocklist.txt
    └── whitelist.txt
  1. Populate your lists - Time to add your domains. For example in my wife’s whitelist, I have the following:
# Adverts
ad.doubleclick.net
clickserve.dartsearch.net

# Email tracking
mask-h2.icloud.com

Note: Comments can be added with a # at the beginning of each line.

Step 3: Add and Commit Files to Your Repository

Now, add the files to your repository and commit them.

  1. Add Files:

    git add .
    

    This adds all files in the current directory (custom-blocklists) to the repository.

  2. Commit Changes:

    git commit -m "Initial commit: Pi-Hole blocklist configuration"
    

    Replace m with -c for a commit message.

Step 4: Push Changes to Gitea

After committing, push your changes to the Gitea repository.

  1. Push to Gitea:
    git push origin main:main
    
    Replace origin and main with your repo name and branch if necessary.

Replace your-gitea-server and path/to/repo.git with your Gitea URL and path.

Step 5: Add your lists to pi-hole

Note: For this example I am using pihole v6, so your layout may differ.

  1. Go to Lists - Add the url to the address field and give it a name
  2. Select the list type - Select either Add blocklist or Add whitelist depending on whether you want to block or allow the list.
  3. Update Gravity - Moment of truth. This can be found by clicking Tools > Update Gravity.
  4. Test - Try out your lists. Go to a website you know which should be allowed or blocked. You can use the Query Log to check if the domain is being blocked or allowed. If it’s not, you may need to adjust your rules.

Note: Query log will show what requests have been approved or denied. So if something is being blocked, then you can filter for blocked requests within a time period and by device. 5. Refine your rules - Based on your testing, refine your rules to ensure they are working as expected. You may need to adjust the order of your lists or add additional conditions.

Best Practices for Maintaining Sanity

  • Regularly Review Your Blocklists: Schedule time to review and update your blocklists from time to time. Utilise the Query Log to identify any issues or anomalies in your rules.
  • Leverage source control: If something goes wrong, you can always revert to a previous version or review changes.
  • Use a Separate Repository for Testing: Create a separate Gitea repository for testing new domains before adding them to your production blocklist.

Wrapping Up

This approach mimics how most people and entities manage public blocklists. It allows for easy updates, testing, and refinement, while also providing a backup plan in case something goes wrong.

By using a public repository of some sort, you control your lists and they are now YOUR lists. You are in control of changes. Public lists are still invaluable, but with this approach, you can manage them more effectively. Happy blocking!