LB ECMP 6 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
add chain=srcnat out-interface="ether3" action=masquerade
add chain=srcnat out-interface="ether4" action=masquerade
add chain=srcnat out-interface="ether5" action=masquerade
add chain=srcnat out-interface="ether6" action=masquerade
/ip route
add check-gateway=ping distance=1 gateway="192.168.1.1,192.168.2.1,192.168.3.1,192.168.4.1,192.168.5.1,192.168.6.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"
add check-gateway=ping distance=1 gateway="192.168.3.1" routing-mark="to-ether3"
add check-gateway=ping distance=1 gateway="192.168.4.1" routing-mark="to-ether4"
add check-gateway=ping distance=1 gateway="192.168.5.1" routing-mark="to-ether5"
add check-gateway=ping distance=1 gateway="192.168.6.1" routing-mark="to-ether6"
/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-connection chain=input in-interface="ether3" new-connection-mark="cm-ether3"
add action=mark-connection chain=input in-interface="ether4" new-connection-mark="cm-ether4"
add action=mark-connection chain=input in-interface="ether5" new-connection-mark="cm-ether5"
add action=mark-connection chain=input in-interface="ether6" new-connection-mark="cm-ether6"
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"
add action=mark-routing chain=output connection-mark="cm-ether3" new-routing-mark="to-ether3"
add action=mark-routing chain=output connection-mark="cm-ether4" new-routing-mark="to-ether4"
add action=mark-routing chain=output connection-mark="cm-ether5" new-routing-mark="to-ether5"
add action=mark-routing chain=output connection-mark="cm-ether6" new-routing-mark="to-ether6"
Credit https://www.o-om.com/2020/11/mikrotik-load-balancing-ecmp-script.html