# Pihole stops working after power outage

**URL:** <https://discourse.pi-hole.net/t/pihole-stops-working-after-power-outage/24975>\
**Category:** General\
**Created:** [October 29, 2019, 2:59pm UTC](https://discourse.pi-hole.net/t/pihole-stops-working-after-power-outage/24975 "2019-10-29T14:59:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cori](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/cori/32/9931_2.png) [@Cori](https://discourse.pi-hole.net/u/Cori)\
**Post date:** [October 29, 2019, 2:59pm UTC](https://discourse.pi-hole.net/t/pihole-stops-working-after-power-outage/24975/1 "2019-10-29T14:59:04Z")

</div>

So this is interesting.. my Pihole fails to come up when there is a power outage.

I figured out that since I have it setup to use 127.0.0.1#5353 to forward DNS requests to DNScrypt which I also installed on my Raspi Zero, it gets stuck because it cannot make any initial resolutions (a catch 22).

To jump start it, I have to go to the DNS settings, change it to use one of the ordinary resolvers such as google, remove DNSSEC, remove the 127.0.0.1#5353 DNS server. Once DNS queries start working again, I can put it back to the way it was and it begins using DNSCrypt again.

Is there a setting to force PiHole to use a fallback resolver? I see one with DNSCrypt but that's no good since PiHole is the initial GW.

Thanks!

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [October 29, 2019, 4:24pm UTC](https://discourse.pi-hole.net/t/pihole-stops-working-after-power-outage/24975/2 "2019-10-29T16:24:35Z")

</div>

It appears that the Pi may be losing track of time when it loses power (Pi's don't have a built in clock). Then, when it starts up, it cannot resolve DNSSEC since the time is not correct, thus cannot connect to an ntp server to set the time.

There are several potential solutions.

1. Put the Pi on a battery backup or UPS so it won't lose power and won't lose time.

2. Install an inexpensive clock module (this is one example [Amazon.com: DS3231 Real Time Clock Module 3.3V/5V with Battery for Raspberry Pi and Arduino by Atomic Market : Industrial & Scientific](https://www.amazon.com/battery-Raspberry-Arduino-Atomic-Market/dp/B01M105UFC?tag=pihole09-20)).

3. You can also set the Pi itself to use an upstream DNS resolver other than Pi-Hole. By default, Pi-Hole sets the DNS resolver in /etc/resolv.conf to the loopback address (assuming that you will want the Pi to use Pi-Hole for DNS resolution). You can do this with local changes to your installed Pi-Hole code:

> [@How do I disable Pi-hole automatic add 127.0.0.1 in resolv.conf](https://discourse.pi-hole.net/t/how-do-i-disable-pi-hole-automatic-add-127-0-0-1-in-resolv-conf/18248):
>
> I'm using Debian9 latest Pi-hole ( Not on raspberry PI, on external self-hosted Server ) How can I avoid every time restart pi-hole auto add nameserver 127.0.0.1 inside /etc/resolv.conf

One note - since you are using a local DNS resolver (unbound, it appears) that does DNSSEC resolution natively, you don't need to (nor do you want to) enable DNSSEC in Pi-Hole as well.

---

<div class="post-metadata">

**Author:** ![Cori](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/cori/32/9931_2.png) [@Cori](https://discourse.pi-hole.net/u/Cori)\
**Post date:** [October 29, 2019, 11:48pm UTC](https://discourse.pi-hole.net/t/pihole-stops-working-after-power-outage/24975/3 "2019-10-29T23:48:17Z")

</div>

Some great information mate thanks alot! Appreciate you taking the time to help me on this!  
Have a good one!

---

<div class="post-metadata">

**Author:** ![Cori](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/cori/32/9931_2.png) [@Cori](https://discourse.pi-hole.net/u/Cori)\
**Post date:** [October 30, 2019, 4:27pm UTC](https://discourse.pi-hole.net/t/pihole-stops-working-after-power-outage/24975/4 "2019-10-30T16:27:04Z")

</div>

So I winded up adding this script to /etc/init.d

```auto
pi@pihole:/etc/init.d $ cat pihole-dns.sh
#!/bin/bash
### BEGIN INIT INFO
# Provides: Pi-hole DNS resolution during a startup after a power failure.
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Description: This script will install a Google DNS nameserver in /etc/resolv.conf
# until the Pi-hole has a chance to start working, then it will switch
# DNS back to localhost 127.0.0.1 so DNS resolution comes from the Pi-hole.
### END INIT INFO
echo "Setting up Google for Startup DNS"
cp /home/pi/startup-dns /etc/resolv.conf
echo "Waiting 1 minute"
sleep 1m
echo "Testing Internet connection and DNS resolution is ok..."
wget -q --spider http://google.com

if [$? -eq 0]; then
    echo "Online"
    echo "Changing back to our default Pi-hole resolver..."
    cp /home/pi/default-dns /etc/resolv.conf
    echo "Done"
else
    echo "Offline"
    echo "Sorry, please try logging into the Pi-hole Admin interface and setting a normal resolver there. Once it starts working, put it back to 127.0.0.1#5300"
fi

```

It requires 2 files to exist:

```auto
$ cat /home/pi/startup-dns
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8

```

and

```auto
$ cat /home/pi/default-dns
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1

```

Those could probably be just included in the script.

If anyone else needs it you may need to tweak it for the correct runlevels and adjust the 1m delay.

Another option would be to just loop the script to check for connectivity and then change it. Feel free to modify it.

To make it work just put it in /etc/init.d/ folder and run:

```auto
$ sudo update-rc.d pihole-dns.sh defaults

```

If something went wrong you can remove it using this:

```auto
$ sudo update-rc.d pihole-dns.sh remove

```
