budiana

Mikrotik Script Auto add route(Gateway)

Mar 8th, 2018
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.59 KB | None | 0 0
  1. Mikrotik Script Auto add route(Gateway)
  2.  
  3. :local GWay [/ip dhcp-client get [find interface="ether1"] gateway];
  4. /ip route add distance=1 gateway=($GWay."%ether1") routing-mark=conn1 scope=255 comment="Auto-Add"
  5.  
  6. ---------------------------------------------------------
  7.  
  8. Mikrotik Limit Speed With Queue Tree
  9.  
  10. /queue type
  11. add kind=pcq name=PCQ-Upload pcq-classifier=src-address \
  12.     pcq-dst-address6-mask=64 pcq-rate=2M pcq-src-address6-mask=64
  13. add kind=pcq name=PCQ-Download pcq-classifier=dst-address \
  14.     pcq-dst-address6-mask=64 pcq-rate=2M pcq-src-address6-mask=64
  15.  
  16. /queue simple
  17. add max-limit=10M/10M name=Limit-All queue=PCQ-Upload/PCQ-Download target=\
  18.     192.168.2.0/24
  19.  
  20.  
  21. Note:
  22. - max-limit=10M/10M: is total bandwidth.
  23. - pcq-rate=2M ; maximum speed for a host is only 2Mb
  24.  
  25. if you want to unlimited speed for one user, you just set pcq-rate=0. It mean that
  26. Queue will share Equally Bandwidth for all user.
  27.  
  28. /queue type
  29. add kind=pcq name=PCQ-Upload pcq-classifier=src-address \
  30.     pcq-dst-address6-mask=64 pcq-rate=0 pcq-src-address6-mask=64
  31. add kind=pcq name=PCQ-Download pcq-classifier=dst-address \
  32.     pcq-dst-address6-mask=64 pcq-rate=0 pcq-src-address6-mask=64
  33.  
  34.  
  35. Mikrotik Unlimit Browsing but Limit Download
  36.  
  37. /ip firewall mangle
  38. add action=mark-connection chain=prerouting connection-bytes=\
  39.     262146-4294967295 in-interface=ether1 new-connection-mark=download \
  40.     protocol=tcp src-port=21,80
  41. add action=mark-packet chain=prerouting connection-mark=download \
  42.     in-interface=ether1 new-packet-mark=download passthrough=no
  43.  
  44. /queue type
  45. add kind=pcq name=shape pcq-classifier=src-address pcq-dst-address6-mask=64 \
  46.     pcq-rate=128k pcq-src-address6-mask=64
  47.  
  48. /queue tree
  49. add max-limit=128k name=Download packet-mark=download parent=global queue=\
  50.     shape
  51.  
  52. Not: ether1 = WAN interface
  53.  
  54. if you have two ISP and configure as load Balancing, you must add two Mangle
  55.  
  56. Ex.
  57. /ip firewall mangle
  58. add action=mark-connection chain=prerouting connection-bytes=\
  59.     262146-4294967295 in-interface=ether1 new-connection-mark=download \
  60.     protocol=tcp src-port=21,80
  61. add action=mark-packet chain=prerouting connection-mark=download \
  62.     in-interface=ether1 new-packet-mark=download passthrough=no
  63.  
  64. /ip firewall mangle
  65. add action=mark-connection chain=prerouting connection-bytes=\
  66.     262146-4294967295 in-interface=ether2 new-connection-mark=download \
  67.     protocol=tcp src-port=21,80
  68. add action=mark-packet chain=prerouting connection-mark=download \
  69.     in-interface=ether1 new-packet-mark=download passthrough=no
  70.  
  71.  
  72. Mikrotik How to Calculate Burst time
  73.  
  74. https://docs.google.com/spreadsheets/d/1qx9OXTscdOBbWzuRSm0hP-eNyO8asUohvijItJ19flo/edit#gid=0
  75. http://www.vshabakeh.com/%D9%85%D8%A7%D8%B4%DB%8C%D9%86-%D8%AD%D8%B3%D8%A7%D8%A8-burst-%DB%8C%D8%A7-burst-calculator-simulator/
  76. https://ip-pro.eu/en/tools/mikrotik_burst_calculator
  77. https://wispcasts.com
  78.  
  79. Mikrotik Load Balancing(NTH Method) 2 WANs(Static IP)
  80.  
  81. /ip address
  82.  add address=103.28.2.254/30 interface=WAN1
  83.  add address=103.28.0.254/30 interface=WAN2
  84.  add address=192.168.168.1/24 interface=bridge-LAN
  85.  
  86. /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
  87.  
  88. /ip firewall mangle
  89. 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
  90. add chain=prerouting in-interface=bridge-LAN connection-mark=conn1 action=mark-routing new-routing-mark=conn1 passthrough=no comment="" disabled=no
  91.  
  92. 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
  93. add chain=prerouting in-interface=bridge-LAN connection-mark=conn2 action=mark-routing new-routing-mark=conn2 passthrough=no comment="" disabled=no
  94.  
  95. /ip firewall nat
  96. add chain=srcnat action=masquerade out-interface=WAN1 comment="" disabled=no
  97. add chain=srcnat action=masquerade out-interface=WAN2 comment="" disabled=no
  98.  
  99. /ip route
  100. add dst-address=0.0.0.0/0 gateway=103.28.2.253 scope=255 target-scope=10 routing-mark=conn1 comment="" disabled=no
  101. add dst-address=0.0.0.0/0 gateway=103.28.0.253 scope=255 target-scope=10 routing-mark=conn2 comment="" disabled=no
  102.  
  103. add dst-address=0.0.0.0/0 gateway=103.28.2.253 comment="" disabled=no
  104. add dst-address=0.0.0.0/0 gateway=103.28.0.253 comment="" disabled=no
  105.  
  106.  
  107. Note: if you have more then 2 WANs you just add:
  108.  
  109. 1. ip --> Address
  110. 2. ip --> firewall -->Mangle
  111. 3. ip --> firewall --> NAT
  112. 4. ip --> route.
  113.  
  114. Example: you have three WANs:
  115.  
  116. /ip firewall mangle
  117. 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
  118. add chain=prerouting in-interface=bridge-LAN connection-mark=conn1 action=mark-routing new-routing-mark=conn1 passthrough=no comment="" disabled=no
  119.  
  120. 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
  121. add chain=prerouting in-interface=bridge-LAN connection-mark=conn2 action=mark-routing new-routing-mark=conn2 passthrough=no comment="" disabled=no
  122.  
  123. /ip firewall nat
  124. add chain=srcnat action=masquerade out-interface=WAN1 comment="" disabled=no
  125. add chain=srcnat action=masquerade out-interface=WAN2 comment="" disabled=no
  126.  
  127. /ip route
  128. add dst-address=0.0.0.0/0 gateway=103.28.2.253 scope=255 target-scope=10 routing-mark=conn1 comment="" disabled=no
  129. add dst-address=0.0.0.0/0 gateway=103.28.0.253 scope=255 target-scope=10 routing-mark=conn2 comment="" disabled=no
  130.  
  131. add dst-address=0.0.0.0/0 gateway=103.28.2.253 comment="" disabled=no
  132. add dst-address=0.0.0.0/0 gateway=103.28.0.253 comment="" disabled=no
  133.  
  134. -------------------Add Config-----------------
  135. /ip address
  136.  add address=X.X.X.X/X interface=WAN3
  137.  
  138. /ip firewall mangle
  139. 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
  140.  
  141. add chain=prerouting in-interface=bridge-LAN connection-mark=conn3 action=mark-routing new-routing-mark=conn3 passthrough=no comment="" disabled=no
  142.  
  143. /ip firewall nat
  144. add chain=srcnat action=masquerade out-interface=WAN3 comment="" disabled=no
  145.  
  146. /ip route
  147. add dst-address=0.0.0.0/0 gateway=X.X.X.X scope=255 target-scope=10 routing-mark=conn3 comment="" disabled=no
  148. add dst-address=0.0.0.0/0 gateway=X.X.X.X comment="" disabled=no
  149. -------------------------------------------------
  150.  
  151. Note: /ip firewall mangle: --> nth=3,3 must equal the amount of your WANs.
Add Comment
Please, Sign In to add comment