Load balancing over multiple gateways

 

Load balancing is the ability to balance traffic across two or more WAN links by using basic routing. When connections are initiated for session like Web, email, video streaming etc, the traffic is distributed over all WAN links. For example, if you have internet service from two ISPs 10Mbps and 5Mbps respectively, you will now have a total bandwidth of 15Mbps. When browsing the internet your browser will open multiple connections to the website, each connection will download a different part of the page, some for images and others for text which makes websites load faster.

Also, network load balancing is mostly used to provide network redundancy so that in the event of an outage on one of the WAN link, access to network resources is still available via the secondary link(s). Link redundancy is a key requirement for business continuity plans and is largely used in combination with critical applications like VPNs and VoIP.

This feature makes it easier for WISP to increase bandwidth and at the same time add redundancy.

Modify the script below to match your router’s WAN interface name and gateway IP addresses.

/ip dhcp-client
add add-default-route=no comment=defconf dhcp-options=hostname,clientid \
    disabled=no interface=WAN1
add add-default-route=no dhcp-options=hostname,clientid disabled=no \
    interface=WAN2
	
/ ip firewall mangle
add chain=prerouting dst-address=192.168.0.0/24  action=accept in-interface=bridge
add chain=prerouting dst-address=192.168.11.0/24  action=accept in-interface=bridge

add chain=prerouting in-interface=WAN1 connection-mark=no-mark action=mark-connection new-connection-mark=WAN1_conn
add chain=prerouting in-interface=WAN2 connection-mark=no-mark action=mark-connection new-connection-mark=WAN2_conn
	
add chain=prerouting  in-interface=bridge connection-mark=no-mark dst-address-type=!local per-connection-classifier=both-addresses:2/0 action=mark-connection new-connection-mark=WAN1_conn 
add chain=prerouting  in-interface=bridge connection-mark=no-mark dst-address-type=!local per-connection-classifier=both-addresses:2/1 action=mark-connection new-connection-mark=WAN2_conn
	
add chain=prerouting connection-mark=WAN1_conn in-interface=bridge action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=bridge action=mark-routing new-routing-mark=to_WAN2
	
add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1     
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2

/ ip route
add dst-address=0.0.0.0/0 gateway=192.168.11.1 routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.0.1 routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.11.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.0.1 distance=2 check-gateway=ping

/ ip firewall nat 
add chain=srcnat out-interface=WAN1 action=masquerade
add chain=srcnat out-interface=WAN2 action=masquerade