Failover Script with Dynamic Wans

I found this script in the wiki. It is a simple dual wan failover. Is there a way to make this script work with dynamic wan addresses without actually having to input the public wan ip address?

{

local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 4.2.2.2 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} else={ :if ([/ip route get [find comment="Default Route"] distance]=3) do={:log info "Main Gateway Up"; /ip route set [find comment="Default Route"] distance=1} } }

Hi,

if you have dynamic wan-addresses I assume that you use dhcp-client on that interfaces?

If so, then just set different distances “Default Route Distance” within the dhcp-client.

So when your main wan (with lower distance) drops, the other route will be active. This works for physical disconnects.
For logical disconnects a small script to renew the lease time of the dhcp-client (maybe within 1 minute) can be useful to achieve a failover within a certain amount of time.

Not the best solution, but easier.

What is the difference between a physical disconnect and a logical disconnect?

Unless your gateway is local you can just use the check gateway option on the route with ping. So set your dhcp client not to add route, add static routes with different distances. Add the check gatway ping to default route. It will failover within 30 seconds.

Example DSL static address with some providers use cascading routing and put you gateway local on your modem. You can always ping the gateway this way and then you need to use scripting.

Sorry to be unclear.

physical was meant if there is a problem on layer 1 (link drops)
logical was meant if the there is a problem on layer 2/3 (eg dhcp client renew won´t work)