特别鸣谢:感谢Ron大佬不厌其烦地指导和讲解,让我的家庭网络速度跑满了带宽
记录一下自己用到的一些简单的防火墙规则和脚本
防火墙规则如下
1 2 3 4 5 6
| /ip firewall filter add action=accept chain=input connection-state=established,related add action=drop chain=input connection-state=invalid in-interface=Internet add action=drop chain=input in-interface=Internet protocol=icmp src-address=!192.168.66.0/24 add action=drop chain=input in-interface=Internet protocol=tcp dst-port=53,123,8291 add action=drop chain=input in-interface=Internet protocol=udp dst-port=53,123,8291
|
解释:
点开New Terminal 输入下面代码
1 2 3 4 5 6
| /ip firewall filter #定义防火墙 add action=accept chain=input connection-state=established,related #放行进入路由器的数据 add action=drop chain=input connection-state=invalid in-interface="PPPOE拔号的名称" #丢掉进入路由器无效数据 add action=drop chain=input in-interface="PPPOE拔号的名称" protocol=icmp src-address=! 本地IP段 ## ! 是除了本地IP段都不能PING通。 add action=drop chain=input in-interface="PPPOE拔号的名称" protocol=tcp dst-port="WINBOX端口或是53之类的' add action=drop chain=input in-interface="PPPOE拔号的名称" protocol=ucp dst-port="WINBOX端口或是53之类的'
|
担心WR330性能不够,后面这几条规则暂时没有加入
1 2 3 4
| add action=drop chain=input src-address list=Blockip ## blcokip也可以定义为其他名称,主要是将所有被DROP的IP列入address list里面,自动禁止掉。 add action=add src to address list chain=input in-interface="PPPOE拔号的名称" protocol=tcp any-port=!53 ##除了53端口,其他扫描端口的IP全部DROP加入address list地址列表里 add action=add src to address list chain=input in-interface="PPPOE拔号的名称" protocol=ucp any-port=!53 ##除了53端口,其他扫描端口的IP全部DROP加入address list地址列表里 add action=drop chain=input src-address list=Blockip ## blcokip也可以定义为其他名称,主要是将所有被DROP的IP列入address list里面,自动禁止掉。
|
自动获取公网IP并抓取到WireGuard接口的脚本如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| :delay 30s :global cfu do={ :local cfi “Zone ID”; :local cfr “Record ID”; :local cfe “CF Account Email”; :local cfk “Global_API_KEY”; :local cfd “用来解析公网IP的完整域名”; :local currentIP [/ip address get [/ip address find interface=CT_dial ] address]; :local cfa [:pick $currentIP 0 [:find $currentIP “/“]]; /tool fetch mode=https http-method=put url=”https://api.cloudflare.com/client/v4/zones/$cfi/dns_records/$cfr"\ http-header-field=”content-type:application/json,X-Auth-Email:$cfe,X-Auth-Key:$cfk” http-data=”{"type":"A","name":"$cfd","content":"$cfa"}” output=none } $cfu
:global ipaddr [/ip address get [/ip address find interface=Internet] address] :set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)] >> :log info [/ip firewall nat set [/ip firewall nat find comment="vm wireguard"] dst-address=$ipaddr]
|
解释:
上面的DDNS脚本详见 ROS cloudflare DDNS相关脚本
1 2 3 4
| :global ipaddr [/ip address get [/ip address find interface=PPPOE拔号的名称] address] #定义ipaddr为公网IP :set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)] #抓取ipaddr
:log info [/ip firewall nat set [/ip firewall nat find comment="自定义WG或其他应用名称"] dst-address=$ipaddr] #将公网IP加入WG应用接口对应的目标地址
|