Mikrotik Router Load Balancing Script
To configure Mikrotik Script for 2 WAN Load Balancing, follow these steps:
Connect your Mikrotik router to both WAN links.
Open Winbox and connect to your Mikrotik router.
Click on "New Terminal" from the toolbar.
Type in the following script:
# Set up two WAN interfaces
/interface ethernet
set ether1 name=WAN1
set ether2 name=WAN2
# Set up IP addresses for WAN interfaces
/ip address
add address=192.168.1.2/24 interface=WAN1
add address=192.168.2.2/24 interface=WAN2
# Create a new gateway group
/ip route
add gateway=192.168.1.1 check-gateway=ping distance=1
add gateway=192.168.2.1 check-gateway=ping distance=1
add dst-address=0.0.0.0/0 gateway-group=WANs
# Set up load balancing
/ip firewall mangle
add chain=prerouting in-interface=LAN action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting in-interface=LAN action=mark-connection new-connection-mark=WAN2_conn passthrough=yes
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 rule
add dst-address=0.0.0.0/0 action=lookup table=to_WAN1
add dst-address=0.0.0.0/0 action=lookup table=to_WAN2
Modify the script according to your network configuration. Replace the WAN interface names, IP addresses, and gateways with your own.
Run the script by clicking on the "Run Script" button from the toolbar.
Test the load balancing by connecting to the internet from a device on your LAN. The traffic should be distributed across both WAN links.
That's it! Your Mikrotik router is now configured for load balancing across two WAN links.
# Enable NAT
/ip firewall nat
add chain=srcnat out-interface=WAN1 action=masquerade
add chain=srcnat out-interface=WAN2 action=masquerade