|
|
安装x86的ros。接入三个网卡,网卡1管理,网卡2作为lan并dhcp。网卡3复制vlan多拨。
脚本开启nat1+upnp。并且针对ipv4和ipv6做好路由。v4进行负债均衡。v6全体下发公网ip。并且都是打了特征避免流量迷路,同时进行了负载均衡设置。全适应。
一号口为5网段,2号口为13网段,保障1号口与二号口之间内网设备可以畅通链接。(脚本全部运行后由winbo人工选择要拨号开启的线路)
并且设置了应对突然断线,重拨等应对。设置了dhcp。同时满足静态ip的访问等。具体脚本如下,但是实际使用发现存在分配dhcp为何无法上网?或者dhcp失败,或者其他情况。
请ros大神以及ai玩家完善并修复该脚本,这样大家都可以用上方便的ros。
也增加了容器面板的配合监控。
主要是想多拨来给pcdn设备使用。大家应该也有这个需求,ros性能比较好。
我实在用ai搞了好久,几个ai互相改,只能搞成这样了,几个版本,我就给一个最后的吧,大家再次基础上操作。也欢迎解答疑问。
==============================================
# =====================================================================
# 模块一:MikroDash 看板专属只读 API 账户激活
# =====================================================================
/user remove [find name="mikrodash_user"]
/user group remove [find name="mikrodash_group"]
/user group add name=mikrodash_group policy=read,api
/user add name="mikrodash_user" group=mikrodash_group password="dash_admin_888" comment="MikroDash Monitor Account"
/ip service set api disabled=no port=8728
:put "=== ✅ 模块一:API 只读账户覆盖刷新成功 ==="
/delay 1s
# =====================================================================
# 模块二:ROS v7 专属内核策略路由表(FIB)注册
# =====================================================================
/routing table remove [find name~"to_"]
/routing table add name=to_129-1 fib
/routing table add name=to_129-2 fib
/routing table add name=to_129-3 fib
/routing table add name=to_59-1 fib
/routing table add name=to_59-2 fib
/routing table add name=to_59-3 fib
/routing table add name=to_40-1 fib
/routing table add name=to_40-2 fib
/routing table add name=to_40-3 fib
:put "=== ✅ 模块二:v7 核心路由表规则覆盖完毕 ==="
/delay 1s
# =====================================================================
# 🧱 模块三:物理 3 号网口 VLAN 铺设与 PPPoE 静默创建
# =====================================================================
/interface pppoe-client remove [find name~"pppoe-129"]
/interface pppoe-client remove [find name~"pppoe-59"]
/interface pppoe-client remove [find name~"pppoe-40"]
/interface macvlan remove [find name~"vif-129-"]
/interface macvlan remove [find name~"vif-59-"]
/interface macvlan remove [find name~"vif-40-"]
/interface vlan remove [find name="vif-129"]
/interface vlan remove [find name="vif-59"]
/interface vlan remove [find name="vif-40"]
/interface vlan add interface=ether3 name="vif-129" vlan-id=129
/interface vlan add interface=ether3 name="vif-59" vlan-id=59
/interface vlan add interface=ether3 name="vif-40" vlan-id=40
# 129 号段 Macvlan 与 PPPoE 矩阵
/interface macvlan add name="vif-129-1" interface="vif-129" mac-address="00:00:00:00:00:A1"
/interface macvlan add name="vif-129-2" interface="vif-129" mac-address="00:00:00:00:00:A2"
/interface macvlan add name="vif-129-3" interface="vif-129" mac-address="00:00:00:00:00:A3"
/interface pppoe-client add name="pppoe-129-1" interface="vif-129-1" user="XXXX" password="XXXX"disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
/interface pppoe-client add name="pppoe-129-2" interface="vif-129-2" user= "XXXX"password="XXXX" disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
/interface pppoe-client add name="pppoe-129-3" interface="vif-129-3" user="XXXX" password="XXXX"disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
# 59 号段 Macvlan 与 PPPoE 矩阵
/interface macvlan add name="vif-59-1" interface="vif-59" mac-address="00:00:00:00:00:A4"
/interface macvlan add name="vif-59-2" interface="vif-59" mac-address="00:00:00:00:00:A5"
/interface macvlan add name="vif-59-3" interface="vif-59" mac-address="00:00:00:00:00:A6"
/interface pppoe-client add name="pppoe-59-1" interface="vif-59-1" user="XXXX" password="XXXX" disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
/interface pppoe-client add name="pppoe-59-2" interface="vif-59-2" user="XXXX" password="XXXX" disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
/interface pppoe-client add name="pppoe-59-3" interface="vif-59-3" user="XXXX" password="XXXX" disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
# 40 号段 Macvlan 与 PPPoE 矩阵
/interface macvlan add name="vif-40-1" interface="vif-40" mac-address="00:00:00:00:00:A7"
/interface macvlan add name="vif-40-2" interface="vif-40" mac-address="00:00:00:00:00:A8"
/interface macvlan add name="vif-40-3" interface="vif-40" mac-address="00:00:00:00:00:A9"
/interface pppoe-client add name="pppoe-40-1" interface="vif-40-1" user=user="XXXX" password="XXXX"disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
/interface pppoe-client add name="pppoe-40-2" interface="vif-40-2" user=user="XXXX" password="XXXX"disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
/interface pppoe-client add name="pppoe-40-3" interface="vif-40-3" user=user="XXXX" password="XXXX"disabled=yes add-default-route=no use-peer-dns=no max-mru=1492 max-mtu=1492
:put "=== ✅ 模块三:9线 PPPoE 矩阵静默创建完毕 ==="
/delay 1s
# =====================================================================
# 模块四:全局直通白名单、NAT1 榨汁与内核防火墙优化
# =====================================================================
/ip firewall nat remove [find comment~"NAT1_"]
/ip firewall nat remove [find comment~"Default_Masq_"]
/ip firewall raw remove [find comment="DNS_Exemption"]
/ip firewall filter remove [find comment="Drop_Invalid_Packets_Directly"]
/ip firewall mangle remove [find comment="LAN_All_Internal_Bypass"]
/ip firewall address-list remove [find list=LAN_Private_Subnets]
/ipv6 firewall raw remove [find comment="Allow_DHCPv6_Client"]
/ip firewall address-list add list=LAN_Private_Subnets address=10.0.0.0/8
/ip firewall address-list add list=LAN_Private_Subnets address=172.16.0.0/12
/ip firewall address-list add list=LAN_Private_Subnets address=192.168.0.0/16
# 为保障 PCC 负载均衡生效,必须完全禁用系统默认的 FastTrack,否则并发大包会逃逸路由表规则
/ip firewall filter set [find action="fasttrack-connection"] disabled=yes
# LAN 至 LAN (含返回流量) 绕过 PCC,节省 CPU
/ip firewall mangle add chain=prerouting dst-address-list=LAN_Private_Subnets action=accept comment="LAN_All_Internal_Bypass" place-before=0
/ip firewall raw add chain=prerouting protocol=udp dst-port=53 action=accept comment="DNS_Exemption"
/ip firewall filter add chain=input connection-state=invalid action=drop comment="Drop_Invalid_Packets_Directly"
/ip firewall filter add chain=forward connection-state=invalid action=drop comment="Drop_Invalid_Packets_Directly"
/ipv6 firewall raw add chain=prerouting protocol=udp dst-port=546 action=accept comment="Allow_DHCPv6_Client"
# 1. NAT1 榨汁规则 (仅对 UDP 实施 Full-Cone 行为,按最高优先级写入)
/ip firewall nat add chain=srcnat out-interface="pppoe-129-1" action=endpoint-independent-nat protocol=udp comment="NAT1_129-1"
/ip firewall nat add chain=srcnat out-interface="pppoe-129-2" action=endpoint-independent-nat protocol=udp comment="NAT1_129-2"
/ip firewall nat add chain=srcnat out-interface="pppoe-129-3" action=endpoint-independent-nat protocol=udp comment="NAT1_129-3"
/ip firewall nat add chain=srcnat out-interface="pppoe-59-1" action=endpoint-independent-nat protocol=udp comment="NAT1_59-1"
/ip firewall nat add chain=srcnat out-interface="pppoe-59-2" action=endpoint-independent-nat protocol=udp comment="NAT1_59-2"
/ip firewall nat add chain=srcnat out-interface="pppoe-59-3" action=endpoint-independent-nat protocol=udp comment="NAT1_59-3"
/ip firewall nat add chain=srcnat out-interface="pppoe-40-1" action=endpoint-independent-nat protocol=udp comment="NAT1_40-1"
/ip firewall nat add chain=srcnat out-interface="pppoe-40-2" action=endpoint-independent-nat protocol=udp comment="NAT1_40-2"
/ip firewall nat add chain=srcnat out-interface="pppoe-40-3" action=endpoint-independent-nat protocol=udp comment="NAT1_40-3"
# 2. 通用伪装规则 (兜底 TCP/ICMP 控制流)
/ip firewall nat add chain=srcnat out-interface="pppoe-129-1" action=masquerade comment="Default_Masq_129-1"
/ip firewall nat add chain=srcnat out-interface="pppoe-129-2" action=masquerade comment="Default_Masq_129-2"
/ip firewall nat add chain=srcnat out-interface="pppoe-129-3" action=masquerade comment="Default_Masq_129-3"
/ip firewall nat add chain=srcnat out-interface="pppoe-59-1" action=masquerade comment="Default_Masq_59-1"
/ip firewall nat add chain=srcnat out-interface="pppoe-59-2" action=masquerade comment="Default_Masq_59-2"
/ip firewall nat add chain=srcnat out-interface="pppoe-59-3" action=masquerade comment="Default_Masq_59-3"
/ip firewall nat add chain=srcnat out-interface="pppoe-40-1" action=masquerade comment="Default_Masq_40-1"
/ip firewall nat add chain=srcnat out-interface="pppoe-40-2" action=masquerade comment="Default_Masq_40-2"
/ip firewall nat add chain=srcnat out-interface="pppoe-40-3" action=masquerade comment="Default_Masq_40-3"
:put "=== ✅ 模块四:NAT1 穿透引擎与多链路安全闭环部署完毕 ==="
/delay 1s
# =====================================================================
# 模块五:物理断线流量黑洞规则
# =====================================================================
/ip route remove [find comment~"Gate_"]
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_129-1 distance=250 comment="Gate_129-1"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_129-2 distance=250 comment="Gate_129-2"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_129-3 distance=250 comment="Gate_129-3"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_59-1 distance=250 comment="Gate_59-1"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_59-2 distance=250 comment="Gate_59-2"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_59-3 distance=250 comment="Gate_59-3"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_40-1 distance=250 comment="Gate_40-1"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_40-2 distance=250 comment="Gate_40-2"
/ip route add dst-address=0.0.0.0/0 type=blackhole routing-table=to_40-3 distance=250 comment="Gate_40-3"
:put "=== ✅ 模块五:物理掉线防串线黑洞部署完毕 ==="
/delay 1s
# =====================================================================
# 模块六:9路动态 IPv6 索要与 ether2 自动广播下发
# =====================================================================
/ppp profile set [find name="default"] use-ipv6=yes
/ipv6 dhcp-client remove [find comment~"v6_dhcp_"]
/ipv6 address remove [find comment~"v6_lan_"]
{
:local lines {"pppoe-129-1";"pppoe-129-2";"pppoe-129-3";"pppoe-59-1";"pppoe-59-2";"pppoe-59-3";"pppoe-40-1";"pppoe-40-2";"pppoe-40-3"}
:foreach ln in=$lines do={
:local pName ("pool_" . $ln)
:local cmtDhcp ("v6_dhcp_" . $ln)
:local cmtLan ("v6_lan_" . $ln)
:if ($ln = "pppoe-129-1") do={
/ipv6 dhcp-client add interface=$ln request=prefix pool-name=$pName pool-prefix-length=64 add-default-route=yes use-peer-dns=no disabled=no comment=$cmtDhcp
} else={
/ipv6 dhcp-client add interface=$ln request=prefix pool-name=$pName pool-prefix-length=64 add-default-route=no use-peer-dns=no disabled=no comment=$cmtDhcp
}
# 强制标记为 /64 掩码,确保 SLAAC 标准广播给内网下级设备
/ipv6 address add interface=ether2 address=::1/64 from-pool=$pName advertise=yes comment=$cmtLan
}
}
/ipv6 settings set forward=yes accept-router-advertisements=yes
/ipv6 nd set [find default=yes] interface=ether2 advertise-dns=yes advertise-mac-address=yes managed-address-configuration=no other-configuration=no disabled=no
:put "=== ✅ 模块六:IPv6 多前缀并发下发部署成功 ==="
/delay 1s
# =====================================================================
# 模块七:自动化调度大脑(Adaptive_Engine 容错无死角终极重构版)
# =====================================================================
/system script remove [find name="Adaptive_Engine"]
/system scheduler remove [find name="Run_Adaptive_Engine"]
/ip firewall mangle remove [find comment~"MikroDash_PCC_"]
/ip route remove [find comment~"Dyn_"]
/system script add name="Adaptive_Engine" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source='
:local lanIf "ether2"
:local prefixList {"pppoe-129-1";"pppoe-129-2";"pppoe-129-3";"pppoe-59-1";"pppoe-59-2";"pppoe-59-3";"pppoe-40-1";"pppoe-40-2";"pppoe-40-3"}
# 使用字符串拼接以规避 [:toarray ""] 产生空值索引的致命 Bug
:local activeStr ""
:foreach line in=$prefixList do={
:local iface [/interface find name=$line]
:if ([:len $iface] > 0) do={
:if ([/interface get $iface running] = true) do={
:if ([:len $activeStr] > 0) do={
:set activeStr ($activeStr . "," . $line)
} else={
:set activeStr $line
}
}
}
}
:local activeLines [:toarray $activeStr]
:local activeCount [:len $activeLines]
:if ([:len $activeStr] = 0) do={ :set activeCount 0 }
:global lastActiveLinesSignature
:local currentSignature ($activeCount . "-" . [:tostr $activeLines])
:if ($lastActiveLinesSignature != $currentSignature) do={
/ip firewall mangle remove [find comment~"MikroDash_PCC_"]
/ip route remove [find comment~"Dyn_"]
:if ($activeCount > 0) do={
:local masterGate ($activeLines->0)
/ip route add dst-address=0.0.0.0/0 gateway=$masterGate distance=1 comment="Dyn_Main_Stable_Gate"
:for i from=1 to=$activeCount do={
:local line ($activeLines->($i-1))
/ip firewall mangle add chain=input in-interface=$line action=mark-connection new-connection-mark=("conn_" . $line) passthrough=yes comment=("MikroDash_PCC_In_" . $line)
/ip firewall mangle add chain=prerouting in-interface=$line action=mark-connection new-connection-mark=("conn_" . $line) passthrough=yes comment=("MikroDash_PCC_In_" . $line)
}
:for i from=1 to=$activeCount do={
:local line ($activeLines->($i-1))
/ip firewall mangle add chain=prerouting in-interface=$lanIf dst-address-type=!local connection-state=new dst-address-list=!LAN_Private_Subnets action=mark-connection new-connection-mark=("conn_" . $line) passthrough=yes per-connection-classifier=("both-addresses-and-ports:" . $activeCount . "/" . ($i-1)) comment=("MikroDash_PCC_Core_" . $line)
}
:for i from=1 to=$activeCount do={
:local line ($activeLines->($i-1))
:local table ("to_" . [:pick $line 6 [:len $line]])
/ip firewall mangle add chain=prerouting src-address-list=LAN_Private_Subnets connection-mark=("conn_" . $line) action=mark-routing new-routing-mark=$table passthrough=no comment=("MikroDash_PCC_Out_" . $line)
/ip firewall mangle add chain=output connection-mark=("conn_" . $line) action=mark-routing new-routing-mark=$table passthrough=no comment=("MikroDash_PCC_Out_" . $line)
/ip route add dst-address=0.0.0.0/0 gateway=$line routing-table=$table distance=1 comment=("Dyn_Gate_" . $line)
}
}
:set lastActiveLinesSignature $currentSignature
:log warning ("Adaptive_Engine: 动态多线路由已刷新,当前在线线路数: " . $activeCount)
}'
/system scheduler add name="Run_Adaptive_Engine" interval=15s start-time=startup on-event="Adaptive_Engine"
:put "=== ✅ 模块七:动态调度大脑静默注册就绪(等待后续拨号上线触发) ==="
|
|