Hi everyone,
The script below had been working for ages on my Mikrotik router:
# set variables
:local primaryDNS "172.16.20.10";
:local fallbackDNS "1.1.1.1,8.8.8.8";
:local currentDNS;
:set $currentDNS [/ip dns get servers];
#:log warning "What I got is: $currentDNS"
#:log warning "What I want to see is: $primaryDNS"
:do {
:put [resolve google.com server=$primaryDNS];
if ($currentDNS!=$primaryDNS) do={
:log warning "DNS Failover: Switching to primaryDNS";
/ip dns set servers $primaryDNS
} else={}
} on-error={ :set $currentDNS [/ip dns get servers];
if ($currentDNS!=$fallbackDNS) do={
:log error "DNS Failover: Switching to FallbackDNS";
/ip dns set servers $fallbackDNS;
} else={:log info "Using Failover DNS, Primary Unavailable"}
}
#try to reach google through the primaryDNS
#if it works and we are on a different DNS, set the DNS server to the primaryDNS
#if it works and we are already on the primaryDNS, do nothing
#if we can't reach google and we aren't already on our FallbackDNS, switch to fallback
#if we can't reach google through primaryDNS and we are on the fallback, log that primaryDNS is unavailable
I configured a script in the MikroTik scheduler that points to my Ubuntu Server, which runs Pi-hole in Docker. If the server goes down, the DNS IPs are supposed to failover to 1.1.1.1 and 8.8.8.8. However, it recently stopped working correctly; the system is now stuck on the fallback IPs even though the server is fully operational. When I disable the script and manually set the DNS to the Ubuntu Server IP (172.16.20.10), Pi-hole receives the queries perfectly. But the moment I re-enable the script, the DNS settings immediately switch back to 1.1.1.1 and 8.8.8.8. Could you please help me troubleshoot this?
Thanks