Skip to content

Instantly share code, notes, and snippets.

@joshuapack
Last active Apr 9, 2021
Embed
What would you like to do?
Pi-hole service script, to correct time if using DNSSEC
# 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
[Unit]
Description=Pi-hole DNS Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/env sh /home/pi/DNS/pihole-dns.sh
[Install]
WantedBy=multi-user.target
#!/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
# INSTALLATION
# Double check all paths are correct, mainly /pi/DNS
# sudo cp pihole-dns.service /etc/systemd/system/pihole-dns.service
# To start: sudo systemctl start pihole-dns
# To enable on startup: sudo systemctl enable pihole-dns
# To stop: sudo systemctl stop pihole-dns
# To disable on startup: sudo systemctl disable pihole-dns
# You can check /var/log/syslog for echos.
# enable more logging with DEBUGSYSLOG=1
##############
SCRIPTLOCATION='/home/pi/DNS'
ONLINE=0
DEBUGSYSLOG=0
while [ !$exit_loop ]
do
if [ "$ONLINE" -eq 0 ]; then
if [ "$DEBUGSYSLOG" -eq 1 ]; then
echo "Changing back to our default Pi-hole resolver to check if internet is back on"
fi
cp ${SCRIPTLOCATION}/default-dns /etc/resolv.conf
fi
if [ "$DEBUGSYSLOG" -eq 1 ]; then
echo "Testing Internet connection and DNS resolution is ok..."
fi
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
if [ "$DEBUGSYSLOG" -eq 1 ]; then
echo "Online"
fi
ONLINE=1
else
ONLINE=0
echo "Offline"
echo "Setting up Google's DNS for Startup DNS"
cp ${SCRIPTLOCATION}/startup-dns /etc/resolv.conf
fi
sleep 15s
done
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment