http://www.mikrotik.com/docs/ros/2.8/appex/scripting1
Load-balancing 1
According to the page , it’s easy to make a load balancing RouterOS.
After I try ten times , I never success.
I found the problem is [ :set R1 1.1.1.1] never set value 1.1.1.1 for R1 in IF statement.
I am sure the tool netwatch is work,because netwatch show the status of R1 is down when I turn off the R1 router. And the run-count of system scripts show that the script haved been runned one time.Beause [ :set R1 1.1.1.1] never give value for R1,result of gateway=($R1 . , . $R2) also isn’t correct.If you replace gateway=3.3.3.3.1,you can do /ip router print,and find the gateway was changed successful.
Can anybody can help me ? Thank you, Nick
/ip route add gateway=1.1.1.1,2.2.2.1
/system script set fo source={
:local R1
:local R2
:if ([/tool netwatch get R1 status]=up) do={:set R1 1.1.1.1}
:if ([/tool netwatch get R2 status]=up) do={:set R2 2.2.2.1}
/ip route set [/ip route find dst-address=0.0.0.0/0] \
gateway=($R1 . , . $R2)
}
/tool netwatch add comment=R1 host=1.1.1.1 interval=5s up-script=fo \
down-script=fo
/tool netwatch add comment=R2 host=2.2.2.1 interval=5s up-script=fo \
down-script=fo