Skip to content

Software Engineer at Polygon

Disable/enable Pi-hole using Apple Shortcuts

Pi-hole is my favourite ad-blocking solution. It runs on Raspberry Pi hooked under my desk, and its only purpose is network-wide DNS filtering. “The World’s Greatest Pi-hole Tutorial 2023” by Crosstalk Solutions is an excellent primer if you are new to the subject.

In most cases, it works like a charm, but from time to time, you just want to disable it temporarily. You can stop it via CLI using pihole disable command, but this one required SSH login. It just takes too long, and on a mobile device, this is cumbersome. Look at some examples.

# Disable Pi-hole for 30 seconds
pihole disable 30s
# Disable Pi-hole for 8 minutes
pihole disable 8m

Pi-hole during the installation phase lets us install an optional web interface which also allows us to stop/start blocking. This is easier than the previous method but still painful, especially on touch devices.

Disable/enable ad blocking via Pi-hole Web Interface

Apple Shortcuts for the rescue

I spent a few minutes creating this little shortcut that ticks all the boxes for an easy and quick to use method for flipping between Pi-hole blocking states. I built it once on macOS, but thanks to the iCloud sync, I can also use it on iPadOS and iOS.

Apple Shortcut to disable/enable ad blocking via Pi-hole on macOS Apple Shortcut to disable/enable ad blocking via Pi-hole on iOS

As you can see, calling Pi-hole API requires an authentication key. You can get it using Web Interface or by checking the Pi-hole setup configuration file.

# Get auth key
cat /etc/pihole/setupVars.conf | grep WEBPASSWORD
# Example how to disable Pi-hole using HTTP request
curl "http://pi.hole/admin/api.php?disable=30&auth=${WEBPASSWORD}"
# Example how to enable Pi-hole using HTTP request
curl "http://pi.hole/admin/api.php?enable&auth=${WEBPASSWORD}"

I hope you found it helpful. Until next time, keep on building cool shit 💩

Comments

  • S
    Shane01638

    I feel there is a bit missing from this tutorial. I would love to see a more in depth guide to get this working, especially if you don't have a mac. I think the iphone interface may be a bit different and trying to duplicate what you have hasn't worked for me.

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Hi. The actions and the interface of Shortcuts app on iOS, iPadOS and macOS are identical. You are right that I should put a bit more details about the commands that I used, so here they are.

      1. Create a "Dictionary" action, where the key is a human readable value (for example 1 minute), the type is ``Numberandvalue` is number of seconds (this is the value that is going to be passed down the the API call).
      2. Next action is "Choose from", where the value is a "Dictionary" created in a first step. Read more about "Magic variables" because it is going to help you a lot to pick the output of previous actions, without creating unnecessary variables.
      3. "Get contents of" takes a Pi-hole API URL as a value. In my case it looks like this. http://pi.hole/admin/api.php?disable=${THE_OUTPUT_OF_STEP_2}&auth=${AUTH_KEY_FROM_CONFIG_FILE}
      4. My last steps are optional — sound and notification. This one I am sure you can adjust to your needs.

      Thanks for feedback and hopefully thats helps 😉

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • T
    Tony

    Another option would be to use the Shortcut Run script over SSH

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      To be fair, I never played around with SSH scripts using Apple Shortcuts. Sounds like a pretty powerful solution. Thanks!

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
      • T
        Tony

        For some reason I couldn’t get your solution to work. Most likely something to do with my using unbound DNS, or my firewall, or something else on my system as what you posted should have worked for me. That’s when I tried the Run script over SSH action. A bit more work to setup (need to copy the public key in the action and add to .ssh/authorized_keys on the pi), but I have it running now.

        👆 you can use Markdown here

        Your comment is awaiting moderation. Thanks!

Leave a comment

👆 you can use Markdown here

Your comment is awaiting moderation. Thanks!