Community discussions

MikroTik App
 
User avatar
broderick
Member Candidate
Member Candidate
Topic Author
Posts: 242
Joined: Mon Nov 30, 2020 7:44 pm

Issues with the "change DNS if Pi-hole is no longer working" script

Thu Feb 10, 2022 11:58 am

Hi ,
I use the script which automatically changes DNS if Pi-hole is no longer working"
:local currentDNS [/ip dns get server]
:local piholeDNS "192.168.3.12"
:local backupDNS "1.1.1.1,1.1.1.2"
:local testDomain "www.google.com"

:if ($currentDNS = $piholeDNS) do={
    :do {
        :resolve $testDomain server $piholeDNS
    } on-error={
        /ip dns set servers=$backupDNS
        /ip dhcp-server network set [find] dns-server=$backupDNS;
    }
} else={
    :do {
        :resolve $testDomain server $piholeDNS
        /ip dns set servers=$piholeDNS
        /ip dhcp-server network set [find] dns-server=$piholeDNS;
    } on-error={}
}

More details here:

viewtopic.php?t=161785


It works flawlessly, but I'd like it not to change also DNS IPs in " /ip dns>" which should always be set as 1.1.1.1 and 1.1.1.2.
I need that only the DNS server in
/ip dhcp-server network
should switch between 192.168.3.1 (my router Ip) and 192.168.3.12 (my pihole ip address) when the server in which pihole is installed is down.
Could you help me change it..if possible?
Thanks
 
Sob
Forum Guru
Forum Guru
Posts: 9120
Joined: Mon Apr 20, 2009 9:11 pm

Re: Issues with the "change DNS if Pi-hole is no longer working" script

Thu Feb 10, 2022 2:08 pm

Just remove the lines starting with "/ip dns set servers=".

But relying on DHCP is not very good solution. Let's say that client first gets Pi-hole as resolver. Then it goes down, so you change DHCP settings, but that won't change client's config immediatelly, it will only happen when it renews DHCP lease. It can take several minutes or even hours, depending on configured lease time. And same thing will happen when client has backup server and Pi-hole becomes available again.
 
User avatar
broderick
Member Candidate
Member Candidate
Topic Author
Posts: 242
Joined: Mon Nov 30, 2020 7:44 pm

Re: Issues with the "change DNS if Pi-hole is no longer working" script

Thu Feb 10, 2022 3:20 pm

Just remove the lines starting with "/ip dns set servers=".

But relying on DHCP is not very good solution. Let's say that client first gets Pi-hole as resolver. Then it goes down, so you change DHCP settings, but that won't change client's config immediatelly, it will only happen when it renews DHCP lease. It can take several minutes or even hours, depending on configured lease time. And same thing will happen when client has backup server and Pi-hole becomes available again.
ok, I'm going to test it either way, and see what is going to happen exactly.
I wanted DNS-SERVER in ip dhcp-server network to switch to my router IP 192.168.3.1 (while dns set back to 1.1.1.1 and 1.1.1.2) when pihole is down, just to enable my mikrotik device to use the cache.

Thanks

Who is online

Users browsing this forum: Benzebub, tdw and 17 guests