Advertisement
budiana

106. Mikrotik Load Balancing(PPC Method) 2 WANs(Static IP) P

Mar 8th, 2018
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.33 KB | None | 0 0
  1. Mikrotik Load Balancing(PPC Method) 2 WANs(Static IP)
  2.  
  3. You can contact me: plus.google.com/+PhallaCCMT; youtube.com/phallaccmt; facebook.com/Phalla.CCMT; twitter.com/PhallaCCMT and Phalla.CCMT@gmail.com
  4.  
  5.  
  6. Script:
  7.  
  8. /ip address
  9.  add address=103.28.2.254/30 interface=WAN1
  10.  add address=103.28.0.254/30 interface=WAN2
  11.  add address=192.168.2.1/24 interface=bridge-LAN
  12.  
  13. /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
  14.  
  15. /ip firewall mangle
  16.  add chain=input in-interface=WAN1 action=mark-connection new-connection-mark=WAN1_conn
  17.  add chain=input in-interface=WAN2 action=mark-connection new-connection-mark=WAN2_conn
  18.  
  19.   add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
  20.  add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2
  21.  
  22.   add chain=prerouting dst-address=103.28.2.252/30 action=accept in-interface=bridge-LAN
  23.  add chain=prerouting dst-address=103.28.0.252/30 action=accept in-interface=bridge-LAN
  24.  
  25.   add chain=prerouting dst-address-type=!local in-interface=bridge-LAN per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
  26.  add chain=prerouting dst-address-type=!local in-interface=bridge-LAN per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes
  27.  
  28.   add chain=prerouting connection-mark=WAN1_conn in-interface=bridge-LAN action=mark-routing new-routing-mark=to_WAN1
  29.  add chain=prerouting connection-mark=WAN2_conn in-interface=bridge-LAN action=mark-routing new-routing-mark=to_WAN2
  30.  
  31. /ip firewall nat
  32.  add chain=srcnat out-interface=WAN1 action=masquerade
  33.  add chain=srcnat out-interface=WAN2 action=masquerade
  34.  
  35. /ip route
  36.  add dst-address=0.0.0.0/0 gateway=103.28.2.253 routing-mark=to_WAN1 check-gateway=ping
  37.  add dst-address=0.0.0.0/0 gateway=103.28.0.253 routing-mark=to_WAN2 check-gateway=ping
  38.  
  39.   add dst-address=0.0.0.0/0 gateway=103.28.2.253 distance=1 check-gateway=ping
  40.  add dst-address=0.0.0.0/0 gateway=103.28.0.253 distance=2 check-gateway=ping
  41.  
  42.  
  43. Note: if you have more then 2 WANs you just add:
  44.  
  45. 1. ip --> Address
  46. 2. ip --> firewall --> Mangle
  47. 3. ip --> firewall --> NAT
  48. 4. ip --> route.
  49.  
  50. Example: you have three WANs:
  51.  
  52. /ip address
  53.  add address=103.28.2.254/30 interface=WAN1
  54.  add address=103.28.0.254/30 interface=WAN2
  55.  add address=192.168.2.1/24 interface=bridge-LAN
  56.  
  57. /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
  58.  
  59. /ip firewall mangle
  60.  add chain=input in-interface=WAN1 action=mark-connection new-connection-mark=WAN1_conn
  61.  add chain=input in-interface=WAN2 action=mark-connection new-connection-mark=WAN2_conn
  62.  
  63.  add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
  64.  add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2
  65.  
  66.  add chain=prerouting dst-address=103.28.2.252/30 action=accept in-interface=bridge-LAN
  67.  add chain=prerouting dst-address=103.28.0.252/30 action=accept in-interface=bridge-LAN
  68.  
  69.  add chain=prerouting dst-address-type=!local in-interface=bridge-LAN per-connection-classifier=both-addresses-and-ports:3/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
  70.  add chain=prerouting dst-address-type=!local in-interface=bridge-LAN per-connection-classifier=both-addresses-and-ports:3/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes
  71.  
  72.  add chain=prerouting connection-mark=WAN1_conn in-interface=bridge-LAN action=mark-routing new-routing-mark=to_WAN1
  73.  add chain=prerouting connection-mark=WAN2_conn in-interface=bridge-LAN action=mark-routing new-routing-mark=to_WAN2
  74.  
  75. /ip firewall nat
  76.  add chain=srcnat out-interface=WAN1 action=masquerade
  77.  add chain=srcnat out-interface=WAN2 action=masquerade
  78.  
  79. /ip route
  80.  add dst-address=0.0.0.0/0 gateway=103.28.2.253 routing-mark=to_WAN1 check-gateway=ping
  81.  add dst-address=0.0.0.0/0 gateway=103.28.0.253 routing-mark=to_WAN2 check-gateway=ping
  82.  
  83.  add dst-address=0.0.0.0/0 gateway=103.28.2.253 distance=1 check-gateway=ping
  84.  add dst-address=0.0.0.0/0 gateway=103.28.0.253 distance=2 check-gateway=ping
  85.  
  86.  
  87. --------------------Add Config--------------------------
  88. /ip address
  89.  add address=X.X.X.X/X interface=WAN3
  90.  
  91. /ip firewall mangle
  92.  add chain=input in-interface=WAN3 action=mark-connection new-connection-mark=WAN3_conn
  93.  add chain=output connection-mark=WAN3_conn action=mark-routing new-routing-mark=to_WAN3
  94.  add chain=prerouting dst-address=X.X.X.X/X action=accept in-interface=bridge-LAN
  95.  add chain=prerouting dst-address-type=!local in-interface=bridge-LAN per-connection-classifier=both-addresses-and-ports:3/2 action=mark-connection new-connection-mark=WAN3_conn passthrough=yes
  96.  add chain=prerouting connection-mark=WAN3_conn in-interface=bridge-LAN action=mark-routing new-routing-mark=to_WAN3
  97.  
  98. /ip firewall nat
  99.  add chain=srcnat out-interface=WAN3 action=masquerade
  100.  
  101. /ip route
  102.  add dst-address=0.0.0.0/0 gateway=X.X.X.X/X routing-mark=to_WAN3 check-gateway=ping
  103.  add dst-address=0.0.0.0/0 gateway=X.X.X.X/X distance=1 check-gateway=ping
  104. ------------------------------------------------------------
  105.  
  106. Note: per-connection-classifier=both-addresses-and-ports:3/2 is equal the amount of your WANs.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement