Giter VIP home page Giter VIP logo

pi-hole-setup's Introduction

Pi-hole Setup Notes and Blocking Domains on a Schedule

Setting up my Raspberry Pi to run Pi-hole was fairly straightforward while following the beginner's guide linked below.

The basic steps were:

  • Installing Rapsberry Pi OS, the Raspberry Pi Imager software makes this process very easy.
    • I installed Rapsberry Pi OS Lite, so I used these instructions to make the terminal font larger using sudo dpkg-reconfigure console-setup
  • Assigning a static IP address to the Raspberry Pi on my router.
  • Installing Pi-hole on the Raspberry Pi, and configuring it to run as a DHCP server as well.
    • On some Netgear routers, you might get the following error when trying to set the Raspberry Pi as your DNS Server:
      The IP address conflicts with the WAN IP subnet. Please eneter a different IP address
      
      To fix this you can simply keep your DNS settings at the default which is to let your ISP set your DNS, then reserve any static IP addresses for your Pi and disable DHCP on your router. After that you can point your DNS settings back to the Raspberry Pi. This post from Adam Ayala was helpful in solving that error.

Helpful Links

Notes on setting up scheduled domain blocking

Using the helpful information on Thomas Mayfield's blog post, I created a custom Adlist for sites I wanted to block during certain times of the day.

Custom Adlist - https://raw.githubusercontent.com/artwilton/pi-hole-setup/main/social-media-blocklist.hosts

It's also possible to store an adlist file locally with the file:///file-location syntax. For example: file:///home/pi/adlist.list

Shell Script to Enable and Disable custom Adlist:

#!/bin/bash
#
#block_social_media.sh

sqlite3 /etc/pi/gravity.db "update adlist set enabled = $1 where id = 2;"
pihole restartdns reload-lists
  • Troubleshooting Note: After trying a few different combinations of commands, I eventually found that pihole restartdns reload-lists worked best for consistently enabling and disabling the adlist, without having to restart any services like the pihole restartdns command by itself does.

    pihole -g also seemed to work well but I didn't want to have to rebuild the gravity database outside of its normal schedule, and when looking at the code for enabling and disabling adlists in the Web interface I saw that the Pi-hole devs use pihole restartdns reload-lists as well.

    What I believe also helped was making sure to include bash -lc when running sudo crontab -e, which was the syntax used in Thomas Mayfield's blog post above. According to this post, this forces "cron execution to use your login environment."

Example syntax for crontab which passes a "true" or "false" parameter to the shell script. This would un-block social media websites from 8:00 AM to 11:00 AM.

# m h dom mon dow command
00 8 * * * bash -lc "/home/pi/block_social_media.sh false"
0 11 * * * bash -lc "/home/pi/block_social_media.sh true"

pi-hole-setup's People

Contributors

artwilton avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.