Site Overlay

ROS路由PCC均衡负载脚本

设置VLAN命令
:for i from=1 to=24 do= {/interface vlan add name=(“VLAN”.$i) vlan-id=$i interface=WAN}
设置桥用于拔号
:for i from=1 to=24 do= {/interface bridge add name=(“bridge”.$i) auto-mac=no admin-mac=(“AE:AB:AC:AD:BE:”.($i+10))}
把VLAN加入到桥
:for i from=1 to=24 do= {/interface bridge port add interface=(“VLAN”.$i) bridge=(“bridge”.$i)}
设置PPP拔号
:for i from=1 to=24 do= {/interface pppoe-client add name=(“pppoe-out”.$i) user=(“user”) password=(“passwd”) interface=(“bridge”.$i)}

::::标记及PCC

/ip firewall mangle
add action=change-mss chain=forward comment=”” disabled=no new-mss=1400 protocol=tcp tcp-flags=syn
:for i from=1 to=24 do= {/ip firewall mangle add action=mark-connection chain=input comment=”” disabled=no in-interface=(“pppoe-out”.$i) new-connection-mark=(“in”.$i) passthrough=yes}
:for i from=1 to=24 do= {/ip firewall mangle add action=mark-routing chain=output comment=”” connection-mark=(“in”.$i) disabled=no new-routing-mark=(“to”.$i) passthrough=yes}
:for i from=1 to=24 do= {/ip firewall mangle add action=mark-connection chain=prerouting comment=”” disabled=no dst-address-type=!local new-connection-mark=($i) passthrough=yes per-connection-classifier=(“both-addresses:24/”.($i-1)) src-address=192.168.1.0/24}

:for i from=1 to=24 do= {/ip firewall mangle add action=mark-routing chain=prerouting comment=($i connection-mark=(“in”.$i) disabled=no new-routing-mark=(“to”.$i) passthrough=yes src-address=192.168.1.0/24}

:::添加路由表
:for i from=1 to=24 do= {/ip route add comment=”” disabled=no distance=1 dst-address=0.0.0.0/0 gateway=(“pppoe-out”.$i) routing-mark=(“to”.$i)}
:for i from=1 to=24 do= {/ip firewall nat add action=masquerade chain=srcnat comment=”” disabled=no out-interface=(“pppoe-out”.$i)}

 

PPC断线自动修改脚本
1分钟运行一次。
复制到system—schduler

{
:local status
:local i “4”
:local x “0”
:local y “0”
:local z “0”
:set x [:len [/interface pppoe-client find running=yes]]
:if ($x<$i) do={
:for ii from=1 to=$i do={
:set status [/interface get [find name=(“pppoe-out”.”$ii”)] running]
:if ($status=true) do={
/ip fir man set [find new-connection-mark=$ii] per-connection-classifier=(“both-addresses:”.”$x”.”/”.”$y”) disable=no;:set y ($y+1)} else={
/ip fir man set [find new-connection-mark=$ii] disable=yes}}}
:if ($x=$i) do={
:set z [:len [/ip fir man find action=”mark-connection” disabled=yes chain=prerouting]]
:if ($z>0) do={
:for ii from=1 to=$i do={
/ip fi man set [find new-connection-mark=$ii] per-connection-classifier=(“both-addresses:”.”$i”.”/”.”$y”) disable=no;:set y ($y+1)}}}}

##说明:from=1 to=4 (pppoe1到4,就是4线pppoe),:local i “4” (4线),根据自己实际修改。
192.168.1.0/24 根据实际修改(内网IP地址段)
pppoe客户端名称,请按照pppoe-out1、pppoe-out2、pppoe-out3、pppoe-out4命名

 

Author: 伍小虎

向各位朋友学习。 鄙人从事:信息化系统(光缆熔接、虚拟化、网络安全等);智能化系统(楼宇对讲系统、智能照明系统、综合布线系统、智能家居系统等);安全技术防范系统(视频监控系统、防盗报警系统、门禁管理系统、停车场管理系统、门客访问系统等)欢迎带项目咨询。

发表评论