Improved Netwatch II

From MikroTik Wiki
Revision as of 19:23, 23 July 2009 by Sandorik (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This setup now changes the distance number on the interfaces that is being used for gateways instead of disabling an interface. That way you could continue to monitor the unused interface to know whether it is actually up or down to the internet.

With these scripts you must use the scheduler to run them. I set mine to every 5 seconds. This will send 5 pings in a row out ether 1 and if all 5 fail it will increase the distance on that port to 3 instead of 1. To start this process you must set your distance on port 1 to 1. The other port that is being used as a failover gateway should be set to a distance of 2. By switching distance on the port instead of disabling it allows you to continue to ping out ether 1 until it pings all 5 times and at that point it will switch back to the main gateway.


script 1:

       :local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 64.233.169.99 interval=3 count=1]=0))};
       :if ($i=5 && [/ip route get [find comment="Default Route"] distance]=1) do={:log info "Main Gateway down"; 
        /ip route set [find comment="Default Route"] distance=3}

script 2:

      :local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 64.233.169.99 interval=3 count=1]=1))}; 
      :if ($i=5 && [/ip route get [find comment="Default Route"] distance]=3) do={:log info "Main Gateway up"; 
      /ip route set [find comment="Default Route"] distance=1}

Suggestion: A trick could be use ping with different sizes and have a different route for each. That would require creating a mangle rule based on packet size and place a routing mark on each.