跳到正文

网络

RouterOS PCC 双线负载均衡:分流、会话保持与三个大坑

PCC 按连接分流完整配置:mangle 打标记、双路由表、递归故障切换兜底,以及 both-addresses 选型和 FastTrack、Hotspot 的兼容结论。

一条线跑满、另一条闲置时才上 PCC:它按连接分流,不是按包,所以单连接该多少还是多少,别指望单线程下载翻倍。

1. 前置:先有两张路由表

/routing table add name=to_WAN1 fib
/routing table add name=to_WAN2 fib

/ip route add dst-address=0.0.0.0/0 gateway=203.0.113.1 routing-table=to_WAN1
/ip route add dst-address=0.0.0.0/0 gateway=198.51.100.1 routing-table=to_WAN2

再给每张表配递归探测做故障切换(见上一篇),断线自动收敛。

2. mangle:认连接、打标记、分流向

# 本地流量和 modem 网段不分流
/ip firewall mangle add chain=prerouting dst-address=203.0.113.0/24 action=accept
/ip firewall mangle add chain=prerouting dst-address=198.51.100.0/24 action=accept

# 按 WAN 口标记入站连接(prerouting 不是 input,保证端口映射回包正确)
/ip firewall mangle add chain=prerouting in-interface=WAN1 \
    action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
/ip firewall mangle add chain=prerouting in-interface=WAN2 \
    action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

# 新连接按地址对 1:1 拆分
/ip firewall mangle add chain=prerouting connection-state=new \
    per-connection-classifier=both-addresses:2/0 \
    action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
/ip firewall mangle add chain=prerouting connection-state=new \
    per-connection-classifier=both-addresses:2/1 \
    action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

# 连接标记转路由标记
/ip firewall mangle add chain=prerouting connection-mark=WAN1_conn \
    action=mark-routing new-routing-mark=to_WAN1 passthrough=no
/ip firewall mangle add chain=prerouting connection-mark=WAN2_conn \
    action=mark-routing new-routing-mark=to_WAN2 passthrough=no

3. 分类器怎么选

分类器行为适合
both-addresses同一对内外 IP 固定走一条线默认选它,网银、登录态不掉线
both-addresses-and-ports拆得更散同一网站多连接被分到不同出口 IP,会话绑定 IP 的站点会踢你下线
src-address只看内网源内网机器数多、行为差异大时用

结论:除非你知道自己在干什么,否则 both-addresses:2/0 + 2/1。

4. 三个大坑

  1. check-gateway 只 ping 光猫:和上一篇一样,探测目标必须穿过整条链路,配递归路由。
  2. Hotspot + PCC:官方明确 Hotspot 自带代理只走主表,PCC 不适用,别硬套。
  3. FastTrack:v7 下和 PCC 兼容(CHR 实测),但排障时先关 FastTrack,看好了再开——它绕过 mangle,会让你怀疑人生。
关于作者

me

写专业、通用的技术教程。