Hello Everyone,
I'm working through a problem that I don't currently have so I can learn more about the scripting language used on the Mikrotik platform.
I have begun implementing a DNS Healthcheck for multi-wan failover script. I'm pretty close to done, but I figured I would ask for input from people who already know what they are doing.
The premise is that I have two wans, when dns fails to resolve on one of them, I want it shut off. The method of failover is automatic, all we need to do is detect when dns isn't working, and disable the routing table associated with this wan.
I have the first few parts done.
1. Setup - I set the dns servers we want to check, and we set the hostnames we want to check. We also set the failover threshold for when a wan should be downed.
2. I loop through the dns servers, and then through the hostnames looking for failures
3. I detect failures over the count, and then we call a function to determine the appropriate wan routing table, and disable it.
The script relies on two static routes for the dns servers forcing them out the correct wan. I don't like this approach, but I couldn't think of any other way to ensure that I could check for the wan to come back up.
I'd like input from the community on how to determine the correct routing table for the wan that is currently not resolving dns. I can't seem to figure out how to find the gateway of the route being used for the dns lookup, and then use that to determine the name of the routing table being used for the default route (0.0.0.0/0) with that same gateway.
I'm already using netwatch and pinging those dns servers on schedule to determine which lan is up/down, and it's working well. I'm just trying to implement something similar to what other vendors have for dns based failover of wan connections.
Script is attached.