Smart PCC Multi-WAN & Recursive Failover (RouterOS v7)

สคริปต์ Smart PCC Load Balance & Recursive Failover (ROS v7)

สร้างคำสั่งรวมความเร็วอินเทอร์เน็ต Multi-WAN ด้วย PCC พร้อมระบบตรวจจับสายหลุดอัตโนมัติ (Recursive Routing Ping 1.1.1.1 / 8.8.8.8) สลับเส้นทางทันใจไร้สะดุด

ตั้งค่าจำนวนเส้นทางและอัตราส่วน (WAN Matrix)

เลือกจำนวนสาย WAN และอัตราส่วนความเร็วเพื่อคำนวณ PCC Classifier อัตโนมัติ

จำนวนสาย WAN:
พอร์ต Bridge หลักของเครือข่ายภายใน
RouterOS v7 PCC CLI Script
# ========================================================
# MikroTik RouterOS v7 Script
# Title: Smart PCC Load Balance & Recursive Failover
# Generated by: SIAM-LOGIN (MTCNA, MTCRE, MTCINE)
# Target ROS Version: RouterOS v7.x
# ========================================================

# 1. สร้าง Routing Tables สำหรับ ROS v7
/routing table
add disabled=no fib name=to_WAN1
add disabled=no fib name=to_WAN2

# 2. ตั้งค่า NAT Masquerade
/ip firewall nat
add chain=srcnat out-interface={wan1_iface} action=masquerade comment="SIAM-LOGIN: NAT WAN1"
add chain=srcnat out-interface={wan2_iface} action=masquerade comment="SIAM-LOGIN: NAT WAN2"

# 3. ตั้งค่า Firewall Mangle (PCC Load Balancing)
/ip firewall mangle
add chain=prerouting dst-address-type=!local in-interface={lan_iface} per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=wan1_conn passthrough=yes comment="SIAM-LOGIN: PCC WAN1 Mark Conn"
add chain=prerouting dst-address-type=!local in-interface={lan_iface} per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=wan2_conn passthrough=yes comment="SIAM-LOGIN: PCC WAN2 Mark Conn"

add chain=prerouting in-interface={lan_iface} connection-mark=wan1_conn action=mark-routing new-routing-mark=to_WAN1 passthrough=no comment="SIAM-LOGIN: Routing Mark WAN1"
add chain=prerouting in-interface={lan_iface} connection-mark=wan2_conn action=mark-routing new-routing-mark=to_WAN2 passthrough=no comment="SIAM-LOGIN: Routing Mark WAN2"

add chain=input in-interface={wan1_iface} action=mark-connection new-connection-mark=wan1_conn passthrough=yes comment="SIAM-LOGIN: Input WAN1 Mark Conn"
add chain=input in-interface={wan2_iface} action=mark-connection new-connection-mark=wan2_conn passthrough=yes comment="SIAM-LOGIN: Input WAN2 Mark Conn"

add chain=output connection-mark=wan1_conn action=mark-routing new-routing-mark=to_WAN1 passthrough=no comment="SIAM-LOGIN: Output Routing Mark WAN1"
add chain=output connection-mark=wan2_conn action=mark-routing new-routing-mark=to_WAN2 passthrough=no comment="SIAM-LOGIN: Output Routing Mark WAN2"

# 4. ตั้งค่า Host Routing สำหรับการเช็คสภาวะการเชื่อมต่อจริง (Host Routes)
/ip route
add dst-address={check_host_wan1}/32 gateway={wan1_gw} scope=10 comment="SIAM-LOGIN: Target Ping WAN1 Check"
add dst-address={check_host_wan2}/32 gateway={wan2_gw} scope=10 comment="SIAM-LOGIN: Target Ping WAN2 Check"

# 5. ตั้งค่า Recursive Routing Failover สำหรับ Main Table
/ip route
add dst-address=0.0.0.0/0 gateway={check_host_wan1} check-gateway=ping distance=1 target-scope=11 comment="SIAM-LOGIN: Main Recursive Default WAN1 (Primary)"
add dst-address=0.0.0.0/0 gateway={check_host_wan2} check-gateway=ping distance=2 target-scope=11 comment="SIAM-LOGIN: Main Recursive Default WAN2 (Backup)"

# 6. ตั้งค่า Recursive Routing สำหรับ Table to_WAN1 และ to_WAN2
/ip route
add dst-address=0.0.0.0/0 gateway={check_host_wan1} check-gateway=ping distance=1 target-scope=11 routing-table=to_WAN1 comment="SIAM-LOGIN: Table WAN1 Main"
add dst-address=0.0.0.0/0 gateway={check_host_wan2} check-gateway=ping distance=2 target-scope=11 routing-table=to_WAN1 comment="SIAM-LOGIN: Table WAN1 Backup to WAN2"

add dst-address=0.0.0.0/0 gateway={check_host_wan2} check-gateway=ping distance=1 target-scope=11 routing-table=to_WAN2 comment="SIAM-LOGIN: Table WAN2 Main"
add dst-address=0.0.0.0/0 gateway={check_host_wan1} check-gateway=ping distance=2 target-scope=11 routing-table=to_WAN2 comment="SIAM-LOGIN: Table WAN2 Backup to WAN1"
โทรปรึกษา แชท LINE นัดสำรวจ