Fail Over บน Mikrotik อย่างใช้ได้จริง Recursive Routing ที่ใช้กับเน็ตแบบไม่ Fix IP ได้ โดย @{tondev} พ่อมดไอที

เปลี่ยนไปใช้เน็ตสำรอง เมื่อเน็ตเส้นหลักล่มแบบใช้งานได้จริง ด้วยการทำ Recursive Routing ซึ่งปกติจะต้องใช้กับระบบที่มีการ Fix IP แต่คุณต้นมี Script (แจกสคริปต์อีกแล้ว) ที่จะช่วยให้เราใช้ความสามารถชั้นเลิศของ Recursive Routing ได้แม้จะใช้เน็ตตามบ้านทั่วไปที่ไม่มี Fix IP

วิธีใช้ ให้ทำการสร้าง PPP Profile แล้วนำสคริปต์ด้านล่าง ในส่วนตั้งแต่ PPP Up ไปป้อนในยังส่วน “On Up” ใน Tab “Scripts” และนำสคริปต์ในส่วน PPP Down ป้อนยังส่วน “On Down” ที่อยู่ในหน้าเดียวกัน หลังจากใส่สคริปต์เรียบร้อยแล้ว ให้แก้ไข ชื่อ Profile ใน pppoe-out ที่เราสร้างขึ้น ให้ตรงกับ Profile ที่มีสคริปต์ เพื่อให้เมื่อ pppoe-out ดังกล่าวมีการเชื่อมต่อ หรือหลุดการเชื่อมต่อ สคริปต์ในส่วน On Up และ On Down จะถูกเรียกขึ้นมาทำงาน

บรรยายโดย @{tondev} พ่อมดไอที จากกลุ่ม Mikrotik ใน Line OpenCHAT https://bit.ly/MikrotikLineOpenCHAT

############PPP UP#######################
:local createRoute do={
 /log info message="Add route $remoteAddress"
 /ip route add dst-address=$dstAddress gateway=$remoteAddress scope=10 target-scope=10 comment=("D".$wan)
 /ip route add dst-address=0.0.0.0/0 gateway=$gateway scope=30 target-scope=10 distance=$distance check-gateway=ping comment=("D".$wan)
}

:local wanArr {
 {
  "remoteAddress"=$"remote-address";
  "dstAddress"=8.8.8.8/32;
  "gateway"=8.8.8.8;
  "distance"=1;
  "wan"="PPPOE_3BB"
 };
 {
  "remoteAddress"=$"remote-address";
  "dstAddress"=8.8.4.4/32;
  "gateway"=8.8.4.4;
  "distance"=2;
  "wan"="PPPOE_AIS"
 };
}

:local intf1 [/interface get $interface];
:foreach w in=$wanArr do={
 if (($w->"wan") = ($intf1->"name")) do={
  $createRoute remoteAddress=($w->"remoteAddress") dstAddress=($w->"dstAddress") gateway=($w->"gateway") distance=($w->"distance") wan=($w->"wan")
 }
}
############PPP UP#######################

############PPP DOWN#######################
:local removeRoute do={ 
 /ip route remove [find comment=$wan]
}

:local gw [/ip route print as-value where gateway=$"remote-address"];
:if (($gw->0->"comment") != "") do={
 $removeRoute wan=($gw->0->"comment")
}
############PPP DOWN#######################