Recursive Failover with dynamic IP

hi,
I set up a recursive failover:

/ip route
add comment="VIA WAN1" disabled=no distance=1 dst-address=1.0.0.1/32 gateway=192.168.122.1 pref-src="" routing-table=main scope=10 suppress-hw-offload=no target-scope=\
    10
add comment="VIA WAN2" disabled=no distance=1 dst-address=9.9.9.9/32 gateway=192.168.9.1 pref-src="" routing-table=main scope=10 suppress-hw-offload=no target-scope=10
add check-gateway=ping comment="default router" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.0.0.1 pref-src="" routing-table=main scope=30 \
    suppress-hw-offload=no target-scope=11
add check-gateway=ping comment=backup disabled=no distance=2 dst-address=0.0.0.0/0 gateway=9.9.9.9 pref-src="" routing-table=main scope=30 suppress-hw-offload=no \
    target-scope=11

Now, I need to handle a dynamic IP on WAN2/ISP2, and I didn’t understand what exactly I should do to make it work.
Could you please help me? Thanks

You need a script that takes the newly assigned gateway in IP DHCP client and put it physically in your routing rules.g
an easy way is to put a comment in each applicable route could be comment=FIXME

Easy to use find command. :wink:

Not sure if this is a good script but one that I just saw…
https://forum.mikrotik.com/posting.php?mode=quote&p=1040529

HEre is another one found used in IP DHCP client script area…
local bound [/ip dhcp-client get [find interface=“ether1ext”] status];
:local leaseIP [/ip dhcp-client get [find interface=“ether1ext”] address];

:if ($bound=“bound”) do={
:if ($leaseIP != $currentIPext) do={
:put “ip address $currentIPext changed to $leaseIP”;
/ip firewall address-list set [/ip firewall address-list find where comment=“extIP-MikroTik”] address=$“leaseIP” disabled=no
:set currentIPext $leaseIP;
}
} else={
/ip firewall address-list set [/ip firewall address-list find where comment=“extIP-MikroTik”] disabled=yes
}

Here is one on my own router…

:if ($bound=1) do={
:local iface $interface
:local gw [ /ip dhcp-client get [ find interface=$“iface” ] gateway ]
/ip route set [ find comment=“PrimaryRecursive” gateway!=$gw ] gateway=$gw
/ip route set [ find comment=“SecondaryRecursive” gateway!=$gw ] gateway=$gw
}

I’d better stay away Mangle setups since I’m not good at deal with it.
Anyway, as for scripts in dhcp clients, I don’t think I perfectly understand what to do first.
Do I need to delete my recursive setup above and put everything in the dhcp client as a script?

Thanks

meanwhile I found this:

http://forum.mikrotik.com/t/simple-failover/163106/1

put this script in the WAN2 dhcp client:

if ($bound = 1) do={
    /ip route
    remove [find where comment=WAN2]
    add dst-address=9.9.9.9 distance=2 scope=10 comment=WAN2 gateway=$"gateway-address"

now, I guess that I need to set recursive failover as it was a static ip as I did above

ok this seems to be working well:


http://forum.mikrotik.com/t/ha-isp-recursive-routing-isp-failover-using-dhcp/166614/1