This example is improved (different) version of round-robin load balancing example. It adds persistent user sessions, i.e. a particular user would use the same source IP address for all outgoing connections. Consider the following network layout:
Step 2: Add both ISP IP address in Mikrotik Address list.
Step 3: Go to mangle and create mangle rules.
Step 4: Then go to nat and create nat rules.
Step 5: Go to routes and create routes rules.
Step 6: Finally configure is done.
Explanation: First we give a code snippet and then explain what it actually does.
/ip address
add address=192.168.170.18/24 comment=ISP_01 interface=ether1 network=192.168.170.0
add address=172.16.1.2/30 comment=ISP_02 interface=ether2 network=172.16.1.0
add address=192.168.0.1/24 comment=Local interface=ether3 network=192.168.0.0
Connections to the router itself:
/ip firewall mangle
add action=mark-connection chain=input in-interface=ether1 \ new-connection-mark=ISP_01_IN
add action=mark-connection chain=input in-interface=ether2 \ new-connection-mark=ISP_02_IN
add action=mark-routing chain=output connection-mark=ISP_01_IN \ new-routing-mark=ISP_01_OUT
add action=mark-routing chain=output connection-mark=ISP_02_IN \ new-routing-mark=ISP_02_OUT
Nating rule:
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1
add action=masquerade chain=srcnat out-interface=ether2
Routing:
/ip route
add check-gateway=ping distance=1 gateway=192.168.170.254 routing-mark=ISP_01_OUT
add check-gateway=ping distance=2 gateway=172.16.1.1 routing-mark=ISP_02_OUT
add check-gateway=ping distance=1 gateway=172.16.1.1,192.168.170.254
END