Thank you all for the info. I used the above to enable disable a group based on time. For those looking for complete steps:
Configuration
- Create a group: Group Management>Groups>Add. E.g. "School"
- Add clients to the Group Configuration: Group Management>Clients>Select Client>Add.
- Set the client to the newly created group in
Group Assignment
(i.e. "School"). Do not put it into the Default group. - Add blacklist of domains: Group Management>Domains:Domain>Add to Blacklist. E.g. To block ALL of youtube, type in:
youtube.com
and selectAdd domain as wildcard
. - Set the blacklist to the group: Under
List of Entries
set theGroup Assignment
to the new group (i.e. "School") - Test it out:
- Enable the Group: Under Group Management>Groups, the
Status
should beEnabled
. - On the target host, open a browser in private mode and go to the blacklisted site. Confirm it is blocked.
- Disable the Group, and confirm that the target machine can visit the blacklisted site.
- Enable the Group: Under Group Management>Groups, the
- You can do this manually whenever needed.
Automatic Scheduling
To set enable the block on regular intervals (e.g. 8am-2pm M-F)
- ssh to your pihole
- Edit the crontab file:
crontab -e
- Add the following lines:
0 8 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 1 where name = '<name of group>'" >> /tmp/pihole_group.log 2>&1
0 14 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 0 where name = '<name of group>'" >> /tmp/pihole_group.log 2>&1
E.g. for group name School
:
0 8 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 1 where name = 'School'" >> /tmp/pihole_group.log 2>&1
0 14 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 0 where name = 'School'" >> /tmp/pihole_group.log 2>&1
If you have any issues, check /tmp/pihole_group.log
. If all is running correctly, the log file will be empty.