Repository navigation
Expand file tree
/
Copy pathLoad Balancing Route
More file actions
81 lines (65 loc) · 8.25 KB
/
Copy pathLoad Balancing Route
File metadata and controls
81 lines (65 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# MikroTik RouterOS 6 - Dual WAN PCC 50/50 with recursive failover
# WAN1: pppoe-out1
# WAN2: pppoe-out2
# LAN interface-list: LAN
#
# IMPORTANT:
# 1) Take a backup/export before importing.
# 2) Run from WinBox/console with Safe Mode enabled.
# 3) Confirm interface-list "LAN" contains ALL LAN/bridge/VLAN interfaces.
# 4) This file assumes both PPPoE clients already exist and are named exactly
# pppoe-out1 and pppoe-out2.
# 5) Import ONCE. Existing rules with the same comments are not duplicated.
# 6) FastTrack is disabled because it can bypass policy-routing processing.
#
# Health-check targets:
# ISP1 -> 1.1.1.1
# ISP2 -> 8.8.8.8
# If either target blocks ICMP, choose a different reliable target.
:if ([:len [/interface pppoe-client find name="pppoe-out1"]] = 0) do={ :error "pppoe-out1 not found - aborting" }
:if ([:len [/interface pppoe-client find name="pppoe-out2"]] = 0) do={ :error "pppoe-out2 not found - aborting" }
:if ([:len [/interface list find name="LAN"]] = 0) do={ :error "Interface list LAN not found - create it and add LAN/VLAN interfaces first" }
# Backup reminder: create backups manually before import.
# Disable automatic default-route installation by the PPPoE clients.
/interface pppoe-client set [find name="pppoe-out1"] add-default-route=no
/interface pppoe-client set [find name="pppoe-out2"] add-default-route=no
# Exclude private, link-local and CGNAT destination ranges from PCC.
:if ([:len [/ip firewall address-list find list="not_in_internet" address="10.0.0.0/8"]] = 0) do={ /ip firewall address-list add list=not_in_internet address=10.0.0.0/8 comment="PCC exclusion RFC1918" }
:if ([:len [/ip firewall address-list find list="not_in_internet" address="172.16.0.0/12"]] = 0) do={ /ip firewall address-list add list=not_in_internet address=172.16.0.0/12 comment="PCC exclusion RFC1918" }
:if ([:len [/ip firewall address-list find list="not_in_internet" address="192.168.0.0/16"]] = 0) do={ /ip firewall address-list add list=not_in_internet address=192.168.0.0/16 comment="PCC exclusion RFC1918" }
:if ([:len [/ip firewall address-list find list="not_in_internet" address="169.254.0.0/16"]] = 0) do={ /ip firewall address-list add list=not_in_internet address=169.254.0.0/16 comment="PCC exclusion link-local" }
:if ([:len [/ip firewall address-list find list="not_in_internet" address="100.64.0.0/10"]] = 0) do={ /ip firewall address-list add list=not_in_internet address=100.64.0.0/10 comment="PCC exclusion CGNAT" }
# Disable FastTrack rules to ensure marked traffic follows policy routing.
/ip firewall filter disable [find action=fasttrack-connection]
# MANGLE: inbound connection affinity.
:if ([:len [/ip firewall mangle find comment="PCC6 01 incoming ISP1"]] = 0) do={ /ip firewall mangle add chain=prerouting action=mark-connection connection-state=new connection-mark=no-mark in-interface=pppoe-out1 new-connection-mark=ISP1_conn passthrough=yes comment="PCC6 01 incoming ISP1" }
:if ([:len [/ip firewall mangle find comment="PCC6 02 incoming ISP2"]] = 0) do={ /ip firewall mangle add chain=prerouting action=mark-connection connection-state=new connection-mark=no-mark in-interface=pppoe-out2 new-connection-mark=ISP2_conn passthrough=yes comment="PCC6 02 incoming ISP2" }
# PCC 50/50 for new LAN-originated connections (TCP, UDP and other IP protocols).
:if ([:len [/ip firewall mangle find comment="PCC6 03 PCC ISP1 50"]] = 0) do={ /ip firewall mangle add chain=prerouting action=mark-connection connection-state=new connection-mark=no-mark in-interface-list=LAN dst-address-type=!local dst-address-list=!not_in_internet per-connection-classifier=both-addresses-and-ports:2/0 new-connection-mark=ISP1_conn passthrough=yes comment="PCC6 03 PCC ISP1 50" }
:if ([:len [/ip firewall mangle find comment="PCC6 04 PCC ISP2 50"]] = 0) do={ /ip firewall mangle add chain=prerouting action=mark-connection connection-state=new connection-mark=no-mark in-interface-list=LAN dst-address-type=!local dst-address-list=!not_in_internet per-connection-classifier=both-addresses-and-ports:2/1 new-connection-mark=ISP2_conn passthrough=yes comment="PCC6 04 PCC ISP2 50" }
# Apply policy routing only to LAN-originated packets.
:if ([:len [/ip firewall mangle find comment="PCC6 05 route LAN ISP1"]] = 0) do={ /ip firewall mangle add chain=prerouting action=mark-routing connection-mark=ISP1_conn in-interface-list=LAN new-routing-mark=to_ISP1 passthrough=no comment="PCC6 05 route LAN ISP1" }
:if ([:len [/ip firewall mangle find comment="PCC6 06 route LAN ISP2"]] = 0) do={ /ip firewall mangle add chain=prerouting action=mark-routing connection-mark=ISP2_conn in-interface-list=LAN new-routing-mark=to_ISP2 passthrough=no comment="PCC6 06 route LAN ISP2" }
# Router-originated replies to connections arriving from either WAN.
:if ([:len [/ip firewall mangle find comment="PCC6 07 router replies ISP1"]] = 0) do={ /ip firewall mangle add chain=output action=mark-routing connection-mark=ISP1_conn new-routing-mark=to_ISP1 passthrough=no comment="PCC6 07 router replies ISP1" }
:if ([:len [/ip firewall mangle find comment="PCC6 08 router replies ISP2"]] = 0) do={ /ip firewall mangle add chain=output action=mark-routing connection-mark=ISP2_conn new-routing-mark=to_ISP2 passthrough=no comment="PCC6 08 router replies ISP2" }
# Recursive health-check host routes, installed in main and both policy tables.
:if ([:len [/ip route find comment="PCC6 probe ISP1 main"]] = 0) do={ /ip route add dst-address=1.1.1.1/32 gateway=pppoe-out1 scope=10 comment="PCC6 probe ISP1 main" }
:if ([:len [/ip route find comment="PCC6 probe ISP2 main"]] = 0) do={ /ip route add dst-address=8.8.8.8/32 gateway=pppoe-out2 scope=10 comment="PCC6 probe ISP2 main" }
:if ([:len [/ip route find comment="PCC6 probe ISP1 to_ISP1"]] = 0) do={ /ip route add dst-address=1.1.1.1/32 gateway=pppoe-out1 routing-mark=to_ISP1 scope=10 comment="PCC6 probe ISP1 to_ISP1" }
:if ([:len [/ip route find comment="PCC6 probe ISP2 to_ISP1"]] = 0) do={ /ip route add dst-address=8.8.8.8/32 gateway=pppoe-out2 routing-mark=to_ISP1 scope=10 comment="PCC6 probe ISP2 to_ISP1" }
:if ([:len [/ip route find comment="PCC6 probe ISP1 to_ISP2"]] = 0) do={ /ip route add dst-address=1.1.1.1/32 gateway=pppoe-out1 routing-mark=to_ISP2 scope=10 comment="PCC6 probe ISP1 to_ISP2" }
:if ([:len [/ip route find comment="PCC6 probe ISP2 to_ISP2"]] = 0) do={ /ip route add dst-address=8.8.8.8/32 gateway=pppoe-out2 routing-mark=to_ISP2 scope=10 comment="PCC6 probe ISP2 to_ISP2" }
# Main routing table: ISP1 primary, ISP2 backup.
:if ([:len [/ip route find comment="PCC6 MAIN ISP1 primary"]] = 0) do={ /ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 distance=1 target-scope=11 check-gateway=ping comment="PCC6 MAIN ISP1 primary" }
:if ([:len [/ip route find comment="PCC6 MAIN ISP2 backup"]] = 0) do={ /ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 distance=2 target-scope=11 check-gateway=ping comment="PCC6 MAIN ISP2 backup" }
# Policy table to_ISP1: ISP1 primary, ISP2 backup.
:if ([:len [/ip route find comment="PCC6 to_ISP1 primary"]] = 0) do={ /ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 routing-mark=to_ISP1 distance=1 target-scope=11 check-gateway=ping comment="PCC6 to_ISP1 primary" }
:if ([:len [/ip route find comment="PCC6 to_ISP1 backup"]] = 0) do={ /ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 routing-mark=to_ISP1 distance=2 target-scope=11 check-gateway=ping comment="PCC6 to_ISP1 backup" }
# Policy table to_ISP2: ISP2 primary, ISP1 backup.
:if ([:len [/ip route find comment="PCC6 to_ISP2 primary"]] = 0) do={ /ip route add dst-address=0.0.0.0/0 gateway=8.8.8.8 routing-mark=to_ISP2 distance=1 target-scope=11 check-gateway=ping comment="PCC6 to_ISP2 primary" }
:if ([:len [/ip route find comment="PCC6 to_ISP2 backup"]] = 0) do={ /ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 routing-mark=to_ISP2 distance=2 target-scope=11 check-gateway=ping comment="PCC6 to_ISP2 backup" }
# NAT per WAN. Existing equivalent masquerade rules may already be present.
:if ([:len [/ip firewall nat find comment="PCC6 NAT ISP1"]] = 0) do={ /ip firewall nat add chain=srcnat action=masquerade out-interface=pppoe-out1 comment="PCC6 NAT ISP1" }
:if ([:len [/ip firewall nat find comment="PCC6 NAT ISP2"]] = 0) do={ /ip firewall nat add chain=srcnat action=masquerade out-interface=pppoe-out2 comment="PCC6 NAT ISP2" }
:put "PCC6 import completed. Check /ip route print detail and /ip firewall mangle print stats."