Community discussions

MikroTik App
 
DarkNate
Forum Guru
Forum Guru
Topic Author
Posts: 1065
Joined: Fri Jun 26, 2020 4:37 pm

Need a bit of help with DNS failover using Netwatch

Mon Nov 14, 2022 9:43 pm

This config works fine, but the issue is, it will “set/change” the DNS even if it's already set correctly and hence hurt the flash memory.

Is there a way to make it smarter to first fetch the value of the existing config, compare it with the input string and make config change only if there's not a match?
/tool netwatch
add disabled=no down-script="/ip dns set use-doh-server=https://dns.google/dns-query" host=192.168.0.4 http-codes=200 interval=10s port=443 start-delay=10s test-script="" thr-http-time=2 timeout=1s type=tcp-conn up-script="/ip dns set use-doh-server=https://private.dns.example/dns-query"
 
ivicask
Member
Member
Posts: 438
Joined: Tue Jul 07, 2015 2:40 pm
Location: Croatia, Zagreb

Re: Need a bit of help with DNS failover using Netwatch

Tue Nov 15, 2022 12:50 am

:local AltDNS 9.9.9.9,1.1.1.1,8.8.8.8 
:local CrSrv [/ip dns get servers]

:if ($CrSrv != $AltDNS) do={
/ip dns
set allow-remote-requests=yes cache-max-ttl=3d cache-size=500KiB \
    max-concurrent-queries=300 max-concurrent-tcp-sessions=50 servers=\
    $AltDNS use-doh-server="" \
    verify-doh-cert=no
}
This is what I use for some scripts, adjust for your needs.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12554
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Need a bit of help with DNS failover using Netwatch  [SOLVED]

Tue Nov 15, 2022 3:16 am

.

{
:local dohurl "https://dns.google/dns-query"
/ip dns; :if ([get use-doh-server]!=$dohurl) do={set use-doh-server=$dohurl}
}

Who is online

Users browsing this forum: No registered users and 9 guests