Skip to content

Instantly share code, notes, and snippets.

@zimbeo
Last active August 15, 2021 02:24
Show Gist options
  • Select an option

  • Save zimbeo/ce677e663ea4aaa4dacfc095d447922f to your computer and use it in GitHub Desktop.

Select an option

Save zimbeo/ce677e663ea4aaa4dacfc095d447922f to your computer and use it in GitHub Desktop.

Updating Groups for Multiple Domains within Pi Hole's Group Management

I'm creating this gist as I had a hard time locating a solution to my issue and I needed to perform multiple updates to the group assigned to a domain within the Group management functionality within Pi Hole.

Thanks to the post below for giving me ideas and pointing me in the right direction. Hopefully this functionality is added within the Web UI later on. https://discourse.pi-hole.net/t/group-management-multi-selection-of-domains-to-add-remove-delete-multiple-to-from-a-group-in-one-go/44671

Find the ID of the group

We first need the ID of the group that we want to set the domains assigned to. You can view these groups in the SQLite DB by running the below query

sudo sqlite3 /etc/pihole/gravity.db "SELECT id,name FROM 'group';"****

View/Update the domainlist_by_group Table

Now we need to update the domainlist_by_group table to set the group_id to correspond to the ID we pulled above for our group. You can first review which groups your domains are assigned to with the below query.

sudo sqlite3 /etc/pihole/gravity.db "SELECT * from domainlist_by_group"

Your domains are likely set to the default group of 0. In my case, I only have one other group created and that has the ID of 1. To update the domainlist_by_group table to assign the domain to your group, run a query similar to below. I wanted to update all of my domains to use the group ID of 1, but you can edit the SQL as needed.

sudo sqlite3 /etc/pihole/gravity.db "UPDATE domainlist_by_group SET group_id = 1 WHERE group_id = 0;"

All in all, I only needed to do this task because my mother has dementia and she is frequently targeted by Phishing attempts and other phone based scams over SMS that use dumbass domains that are just impossible to block. I'm creating her own whitelist as she really only needs access to Apple Services and other sites that are deemed safe and needed a way to bulk update all these entries in the domainlist_by_group table.

Cheers, Zimbeo

References: I referenced the following URL in order to find out what the database looked like for Pi Hole.

https://docs.pi-hole.net/database/gravity/groups/

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