script problem for load balancing

what’s the problem of this script at end for load balancing? it’s not work

# name of interface that should be monitored
# (edit to match your interface name)
:set mInterface2 ether2 ;
:set mInterface3 ether3 ;
:set mInterface4 ether4 ;

# routing mark name used for default route that should be updated
# (edit to match your routing mark name)
:set mRoutingMark SUBNET-LAN ;

/ip address ;
:set mGateway2 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface2] gateway]
:log info $mGateway2
:set mGateway3 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface3] gateway]
:log info $mGateway3
:set mGateway4 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface4] gateway]
:log info $mGateway4

/ip route  add dst-address=0.0.0.0/0 gateway=$mGateway2,$mGateway3,$mGateway4, routing-mark=$mRoutingMark;

and this line is working fine

/ip route  add dst-address=0.0.0.0/0 gateway=$mGateway2 routing-mark=$mRoutingMark;

[/code]

maybe you should better use PCC? ECMP from your example will fail on long-term connections (like ICQ, online games)

chupaka if you can’t solve the problem you want to change the question?
but thank you for your recommendation

not “can’t” but “don’t want to fix a priori fully non-fixable configuration”. I just want to advise much better solution available!

but this is only one script
and i have problem with this script
it’s better that i test al the way and then i can choose the best way to do it
thank you so much for your recommendation for best solution
now I’m waiting to find my answer about the problem in script
regards

PCQ is by definition better than ECMP, and script for it is easier, something like

/ip route set [find routing-mark="GW2"] gateway=[/ip dhcp-client get [find interface=ether2] gateway]
/ip route set [find routing-mark="GW3"] gateway=[/ip dhcp-client get [find interface=ether3] gateway]
/ip route set [find routing-mark="GW4"] gateway=[/ip dhcp-client get [find interface=ether4] gateway]

PCC will connect a client to a server over the same link every time, while ECMP (stabilized with magling and routing) will randomly choose nexthop for each new connection, therefore making downloading with download manager - faster.

You can paste the script into a terminal, to see where the syntax has an error. A comma after the last gateway ?

this is my configuration dear friend in ECMP

/ ip address 
add address=192.168.100.1/24 network=192.168.100.0 broadcast=192.168.100.255 interface=ether1 comment="" disabled=no 

/ ip dhcp-client 
add interface=ether2 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes comment="" disabled=no 
add interface=ether3 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes comment="" disabled=no 
add interface=ether4 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes comment="" disabled=no 

/ ip firewall nat 
add chain=srcnat src-address=192.168.100.0/24 action=masquerade comment="" disabled=no 

/ ip firewall mangle 
add chain=prerouting src-address=192.168.100.0/24 action=mark-routing new-routing-mark=SUBNET-LAN passthrough=yes comment="" disabled=no 

/ ip route 
add dst-address=0.0.0.0/0 gateway=X.X.224.1,X.X.128.1,X.X.160.1 check-gateway=arp scope=255 target-scope=10 routing-mark=SUBNET-LAN comment="" disabled=no

at the end of my configuration i added 3 gateway manually
i want to change this section with this script

:set mInterface2 ether2 ;
:set mInterface3 ether3 ;
:set mInterface4 ether4 ;

:set mRoutingMark SUBNET-LAN ;

/ip address ;
:set mGateway2 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface2] gateway]
:log info $mGateway2
:set mGateway3 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface3] gateway]
:log info $mGateway3
:set mGateway4 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface4] gateway]
:log info $mGateway4

/ip route  add dst-address=0.0.0.0/0 gateway=$mGateway2,$mGateway3,$mGateway4 routing-mark=$mRoutingMark;

ultimate line not working fine

well, you tell about PCC with ‘address’ classifier. if you use ‘address+port’ classifier, it will distribute all conections to the same server via different gateways.

ECMP uses gateways in round-robin manner, but its weakness is routing cache (see http://wiki.mikrotik.com/wiki/Route#Forwarding_Information_Base ). cache is being cleaned every xxx minutes (security reason?), so sometimes new gateway is selected different, so connection having been broken…

ECMP will break connections each ~10 minutes , when routing table flushing occurs

I can avoid it, using my own config similar to PCC

Improved results with PCC for lower ports and ECMP for higher ports

I made a WiKi article

maybe you’ll share your solution? :wink:

mmm… ports?..

and NetworkPRO what’us about my script my friend ?

need to test it

NetworkPro?..

need to do a test and improvement

but what exact rules do you use that are similar to the PCC rules?.. just wonder…

add the dstination to an address list, and keep the nat to that address list with the same gateway

Won’t work.

lists will be very huge if you have many users :wink:

  1. Let ECMP route the first packet of a connection randomly
  2. Mark connection based on outgoing interface, after ECMP has done it’s randomness
  3. Mark routing to force the packets to use the specific route even after route flush occurs.