Guest User

Mikrotik RouterOS v7 - DNS Failover script

a guest
May 2nd, 2024
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | Source Code | 0 0
  1. :local piholedown [/ip firewall nat get ([find where comment="PiHole-DNS"]->0) disabled]
  2. :local piholeDNS "10.0.0.1"
  3. :local testDomain "www.google.com"
  4. :local token "XXXXXXXXXXXXXXXXXX"
  5. :local chatid "YYYYYYY"
  6.  
  7. :if ($piholedown = false) do={
  8.     :do {
  9.         :resolve domain-name="$testDomain" server="$piholeDNS"
  10.     } on-error={
  11.         /ip firewall nat
  12.             disable [find comment="PiHole-DNS"]
  13.             enable [find comment="Google-DNS"]
  14.         :delay 2000ms
  15.         /tool fetch "https://api.telegram.org/bot$token/sendmessage\?chat_id=$chatid&text=Pi-Hole not working! Changed DNS to GoogleDNS." keep-result=no
  16.     }
  17. } else={
  18.     :do {
  19.         :resolve domain-name="$testDomain" server="$piholeDNS"
  20.         /ip firewall nat
  21.             enable [find comment="PiHole-DNS"]
  22.             disable [find comment="Google-DNS"]
  23.         :delay 2000ms
  24.         /tool fetch "https://api.telegram.org/bot$token/sendmessage\?chat_id=$chatid&text=Pi-Hole working! Changed DNS." keep-result=no
  25.     } on-error={}
  26. }
Advertisement
Add Comment
Please, Sign In to add comment