Pi-Hole on a light switch


In my house, my wireless router is connected to a duplex-circuit outlet (where the top is always on, and the bottom one is on a light switch). I set up a Pi-Hole and plugged the Pi (an original B+) into the bottom outlet. Then, I simply made my CenturyLink router “first DNS” go to the Pi-Hole, and “secondary DNS” go to CloudFlare.

Now, whenever I want to disable ad-blocking, I just flip the light switch on. When I want ad-blocking turned off, I just switch the light switch to off. It works pretty well. I am a little concerned about SD Card reliability, so I might switch to a flash drive in the future. (There is a website I visit frequently that advertises for a business (Google Ads) that doesn’t work with the Ad Blocker, for obvious reasons…)


There are several problems with this power-cycling approach:

Pi’s don’t like to be power cycled. When you turn the switch off, that is a sudden loss of power to the Pi, which can corrupt open files, lose the time on the Pi, etc. Pi’s should always be shutdown from software if possible, for a graceful shutdown.

There is already a built-in feature in pihole to disable ad-blocking for a defined time or permanently. This can be done from the web GUI (settings > disable) or from the command line with pihole disable.

Usage: pihole disable [time]
Example: 'pihole disable', or 'pihole disable 5m'
Disable Pi-hole subsystems

  #s                  Disable Pi-hole functionality for # second(s)
  #m                  Disable Pi-hole functionality for # minute(s)

An example - pihole disable 45s will disable Pi-Hole for 45 seconds.

This is also incorrect. There is no concept of “first DNS” and “secondary DNS” in a router. If clients are given more than one DNS to use, they will use both and some of the DNS traffic will bypass Pi-Hole. You should route all DNS traffic to Pi-Hole, which will work if you stop power cycling the device.


Oddly, mine is an Xyzel C1100Z (from CenturyLink), and it actually does have all traffic go through the Pi-Hole when the light switch is on.

UPDATE: This appears to be more of a bug than intentional, now that I think about it. I initially set up my First DNS to the Pi-Hole and Second DNS to CloudFlare. However, like you said, it only worked half of the time. I then deleted all of the text in the Second DNS field, hit Save, and now… it still sends data to CloudFlare despite the field being empty, but only when the Pi is turned off (almost like a backup). Perfect result, but it doesn’t quite make sense. Maybe it is a backup feature in case both DNSs (the Pi-Hole and the empty field) don’t work, but why would it go to the CloudFlare DNS I set rather than CenturyLink DNS? Kind of a mystery. All I know is that it works.

Indeed. That’s why I should probably move to USB, or at least make the SD Card read-only and store the lists on the USB. It’s a work in progress.

I know that, I was reposting this because I have family members who need access to Google Ads but still care about their privacy.

In the end, I know this setup isn’t ideal, it was actually more of a side effect of my router which only has the phone line for DSL next to that specific duplex-mode outlet. I thought it was a neat trick though, with some tweaks…