mirror of
https://github.com/brunofontes/linuxShortcuts.git
synced 2024-11-24 06:34:56 +00:00
Merge branch 'master' of github.com:brunofontes/linuxShortcuts
This commit is contained in:
commit
8cbcbebca8
37
Services/fixDNS.sh
Executable file
37
Services/fixDNS.sh
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
function isDNSWorking() {
|
||||||
|
dnsWorking=$(dig brunofontes.net | grep "ANSWER: 0")
|
||||||
|
}
|
||||||
|
logfile="/var/log/bfontes"
|
||||||
|
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" >> "$logfile"
|
||||||
|
isDNSWorking
|
||||||
|
|
||||||
|
if [ "$dnsWorking" ]; then
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - DNS not working, hour may be wrong. Trying to fix..." >> "$logfile"
|
||||||
|
sudo chattr -i /etc/resolv.conf
|
||||||
|
sudo sed -i 's/127.0.0.2/9.9.9.9/' /etc/resolv.conf 2>>"$logfile"
|
||||||
|
sudo chattr +i /etc/resolv.conf
|
||||||
|
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Forcing time to sync" >> "$logfile"
|
||||||
|
sudo chronyc online 2>"$logfile"
|
||||||
|
sudo chronyc -a 'burst 4/4'
|
||||||
|
i=0
|
||||||
|
while [ "$dnsWorking" -a $i -le 4 ]; do
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Waiting..." >> "$logfile"
|
||||||
|
sleep 20
|
||||||
|
isDNSWorking
|
||||||
|
i=$(( "$i" + 1 ))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$dnsWorking" ]; then
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - FIXED!" >> "$logfile"
|
||||||
|
else
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Script has failed..." >> "$logfile"
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Fixing DNS script has failed. More details on $logfile" >> ~/.log_error
|
||||||
|
fi
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Configuring DNS servers back." >> "$logfile"
|
||||||
|
sudo chattr -i /etc/resolv.conf
|
||||||
|
sudo sed -i 's/9.9.9.9/127.0.0.2/' /etc/resolv.conf
|
||||||
|
sudo chattr +i /etc/resolv.conf
|
||||||
|
fi
|
||||||
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Done" >> "$logfile"
|
11
Services/testDNS.service
Normal file
11
Services/testDNS.service
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Test and fix DNS update with wrong time
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart = /bin/bash /home/bruno/Apps/linuxShortcuts/Services/fixDNS.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
6
Services/updateRootHints.service
Normal file
6
Services/updateRootHints.service
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run update DNS root hints montly
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart = /bin/bash /home/bruno/dns_update_rootHints.sh
|
9
Services/updateRootHints.timer
Normal file
9
Services/updateRootHints.timer
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run update DNS root hints montly
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=monthly
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
Loading…
Reference in New Issue
Block a user