105. Mikrotik Load Balancing(NTH Method) 2 WANs(Static IP)



You can contact me: plus.google.com/+PhallaCCMT; youtube.com/phallaccmt; facebook.com/Phalla.CCMT; twitter.com/PhallaCCMT and Phalla.CCMT@gmail.com

Script:

/ip address
add address=103.28.2.254/30 interface=WAN1
add address=103.28.0.254/30 interface=WAN2
add address=192.168.168.1/24 interface=bridge-LAN

/ip dns set allow-remote-requests=yes cache-max-ttl=1w cache-size=5000KiB max-udp-packet-size=512 servers=103.28.3.187,8.8.8.8

/ip firewall mangle
add chain=prerouting in-interface=bridge-LAN connection-state=new nth=2,1 action=mark-connection new-connection-mark=conn1 passthrough=yes comment="" disabled=no
add chain=prerouting in-interface=bridge-LAN connection-mark=conn1 action=mark-routing new-routing-mark=conn1 passthrough=no comment="" disabled=no

add chain=prerouting in-interface=bridge-LAN connection-state=new nth=2,2 action=mark-connection new-connection-mark=conn2 passthrough=yes comment="" disabled=no
add chain=prerouting in-interface=bridge-LAN connection-mark=conn2 action=mark-routing new-routing-mark=conn2 passthrough=no comment="" disabled=no

/ip firewall nat
add chain=srcnat action=masquerade out-interface=WAN1 comment="" disabled=no
add chain=srcnat action=masquerade out-interface=WAN2 comment="" disabled=no

/ip route
add dst-address=0.0.0.0/0 gateway=103.28.2.253 scope=255 target-scope=10 routing-mark=conn1 comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=103.28.0.253 scope=255 target-scope=10 routing-mark=conn2 comment="" disabled=no

add dst-address=0.0.0.0/0 gateway=103.28.2.253 comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=103.28.0.253 comment="" disabled=no


Note: if you have more then 2 WANs you just add:

1. ip --> Address
2. ip --> firewall -->Mangle
3. ip --> firewall --> NAT
4. ip --> route.

Example: you have three WANs:

/ip firewall mangle
add chain=prerouting in-interface=bridge-LAN connection-state=new nth=3,1 action=mark-connection new-connection-mark=conn1 passthrough=yes comment="" disabled=no
add chain=prerouting in-interface=bridge-LAN connection-mark=conn1 action=mark-routing new-routing-mark=conn1 passthrough=no comment="" disabled=no

add chain=prerouting in-interface=bridge-LAN connection-state=new nth=3,2 action=mark-connection new-connection-mark=conn2 passthrough=yes comment="" disabled=no
add chain=prerouting in-interface=bridge-LAN connection-mark=conn2 action=mark-routing new-routing-mark=conn2 passthrough=no comment="" disabled=no

/ip firewall nat
add chain=srcnat action=masquerade out-interface=WAN1 comment="" disabled=no
add chain=srcnat action=masquerade out-interface=WAN2 comment="" disabled=no

/ip route
add dst-address=0.0.0.0/0 gateway=103.28.2.253 scope=255 target-scope=10 routing-mark=conn1 comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=103.28.0.253 scope=255 target-scope=10 routing-mark=conn2 comment="" disabled=no

add dst-address=0.0.0.0/0 gateway=103.28.2.253 comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=103.28.0.253 comment="" disabled=no

-------------------Add Config-----------------
/ip address
 add address=X.X.X.X/X interface=WAN3

/ip firewall mangle
add chain=prerouting in-interface=bridge-LAN connection-state=new nth=3,3 action=mark-connection new-connection-mark=conn3 passthrough=yes comment="" disabled=no

add chain=prerouting in-interface=bridge-LAN connection-mark=conn3 action=mark-routing new-routing-mark=conn3 passthrough=no comment="" disabled=no

/ip firewall nat
add chain=srcnat action=masquerade out-interface=WAN3 comment="" disabled=no

/ip route
add dst-address=0.0.0.0/0 gateway=X.X.X.X scope=255 target-scope=10 routing-mark=conn3 comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=X.X.X.X comment="" disabled=no
-------------------------------------------------

Note: /ip firewall mangle: --> nth=3,3 must equal the amount of your WANs.

Ref: http://wiki.mikrotik.com/wiki/Load_Balancing
Previous
Next Post »

1 comments:

Write comments