2 WAN-2 LAN load sharing and failover

Hy!

I have a simple MikroTik router configuration. I have 2 WAN connection (WAN1-dhcp client, WAN2-ppp client) and I have 2 LAN (LAN1 and LAN2). The first case resolved by me, but I have no ideo for the second case.

The first case: LAN1 use WAN1 internet and LAN2 use WAN2 internet. I used mangle rule for it:

LAN1: 192.168.10.0/24
LAN2: 192.168.20.0/24

/ip firewall mangle
add action=mark-routing chain=prerouting new-routing-mark=LAN1_to_WAN1 \
    passthrough=yes src-address=192.168.10.0/24
add action=mark-routing chain=prerouting new-routing-mark=LAN2_to_WAN2 \
    passthrough=yes src-address=192.168.20.0/24
/ip firewall nat
add action=masquerade chain=srcnat comment=WAN1 out-interface=ether5-WAN1
add action=masquerade chain=srcnat comment=WAN2 out-interface=ppp-out1-WAN2
/ip route
add distance=1 gateway=10.0.1.254 routing-mark=LAN1_to_WAN1
add distance=1 gateway=ppp-out1-WAN2 routing-mark=LAN2_to_WAN2

It works fine, the LAN1 clients use the WAN1 internet, the LAN2 clients use the WAN2.

The second case:
When there isn’t WAN1 internet connection, the LAN1 use the WAN2 internet, and after the WAN1 internet is go back online, the LAN1 use the WAN1 internet again.
When there isn’t WAN2 internet connection, the LAN2 use the WAN1 internet, and after the WAN2 internet is go back online, the LAN2 use the WAN2 internet again.

How can I do it this failover configuration?

Thanks for Your help!

When you use dhcp client there is no real failover since even if your ISPs router has no internet, the WAN 1 will still be reachable.
The only way for it to work is to power off the ISPs router or unplug the ethernet cable.
You can use recursive failover for the dhcp client if you want to have a proper failover.
Also why dont you use PCC load balancing ?

This is my test lab network. In real world the to WAN has static public address. In the customer has two WAN:
WAN1: 30mb-use for internal wired client
WAN2: 300mb-use for 4k camera, wifi clients

It is static, so again if the network goes down you will still be able to to ping the ISPs gateway unless you unplug the ISPs router.