LB ECMP 2 Line ISP Failover - Mikrotik Script RouterOS

ECMP or Equal Cost Multi Path is a load balancing method that uses the per address-pair connection load balancing method. ECMP allows a router to have more than one gateway to a destination network. Because the method is per address-pair connection, the load balancing system is that each different address on different connections will probably pass through different gateways.

################################################
# LOAD BALANCING ECMP SCRIPT GENERATOR
# Date/Time: 2/13/2021, 8:57:47 PM
# https://fb.me/buananet.pbun
# Load Balancing ECMP (EQUAL COST MULTI PATH)
################################################

/ip firewall nat
add chain=srcnat out-interface="ether1" action=masquerade
add chain=srcnat out-interface="ether2" action=masquerade

/ip route
add check-gateway=ping distance=1 gateway="192.168.1.1,192.168.2.1" 
add check-gateway=ping distance=1 gateway="192.168.1.1" routing-mark="to-ether1"
add check-gateway=ping distance=1 gateway="192.168.2.1" routing-mark="to-ether2"

/ip firewall mangle
add action=mark-connection chain=input in-interface="ether1" new-connection-mark="cm-ether1"
add action=mark-connection chain=input in-interface="ether2" new-connection-mark="cm-ether2"
add action=mark-routing chain=output connection-mark="cm-ether1" new-routing-mark="to-ether1"
add action=mark-routing chain=output connection-mark="cm-ether2" new-routing-mark="to-ether2"
Credit: https://www.o-om.com/2020/11/mikrotik-load-balancing-ecmp-script.html