Yes, you are right, I haven’t tested it thoroughly enough, the output value is “;” regardless whether the command succeeds or fails. So you really have to use the on-error to learn the actual result. So it would look as follows:
:local result yes
:do {tool fetch url="https://1.1.1.1/dns-query\?name=mikrotik.ca%26type=A" output=file dst-path=result \
http-header-field=accept:application/dns-json} on-error={:set result no}
:if $result do={
/ip dns set servers="" use-doh-server=https://1.1.1.1/dns-query
} else={
/ip dns set servers=8.8.8.8 use-doh-server=""
}
(use of the result string as a variable name has nothing to do with its use as a name of the destination file for the :tool fetch)
This is an example of where the context makes a difference. :do is a command itself, and on-error is one of its parameters; do= is a parameter of an :if command. One of other symptoms of ROS’ tolerance is that you may omit the parameter name for some mandatory parameters. So instead of the proper :do command={:put “this”}, you can abbreviate to :do {:put “this”}. With :if, it is the same case: the proper syntax is actually :if condition=($a=$b) do={:put “equals”}, but most people write just :if ($a=$b) do={:put “equals”}
Good. And now please explain me the idea behind hiding where you browse from your ISP or government when you can, but cowardly reverting to plaintext DNS whenever it fails.
There are not so many DoH servers out there (yet?), so it is not a big deal for an ISP with a gun (government’s or other) aimed at their head to prohibit access to all of them, nor to identify eventual newly appearing ones from your traffic alone.
It not so much what I need, but more that I can do
DNS is one of the things that ISP still has control over (until DoH and other solution)
Reverting to normal DNS is needed, since there are not fail over or priority on the RouterOS DNS. If DoH server stops, everything stops.
When there are more DoH servers out there, it may be a better solution to use an another DoH server as fail over.