2020 Update:
Nowadays modern Linux distributions, including Raspbian, use systemd instead of old style SysV as init system. For downstream compatibility SysV is only emulated by systemd but will lose support more and more by time so
you should not use SysV anymore, in particular /etc/rc.local
!
For more information about this have a look at Compatibility with SysV.
With the endless loop in the script it should run in the background as service so you can use a systemd service defined with a Unit file. Here is a simple example for your script. Create it with:
rpi ~$ sudo systemctl --force --full edit dnscheck.service
In the empty editor insert these statements, save them and quit the editor:
[Unit]
Description=Check DNS queries
After=multi-user.target
[Service]
ExecStart=/usr/bin/python3 /home/pi/dnscheck.py
[Install]
WantedBy=multi-user.target
It may be possible that this is too simple and you have to add some more settings for a needed environment. Have a look at man systemd.unit
and man systemd.service
for additional conditions.
Enable and monitor the service with:
rpi ~$ sudo systemctl enable --now dnscheck.service
rpi ~$ systemctl status dnscheck.service
The text output of the script you will find in the journal:
rpi ~$ journalctl -b -e