配置基于 Mikrotik RouterOS 7.6。
[叮当网]
[IPIP]
[RealIP数据库]
在Linux上运行以下脚本可以获取CN IP列表:```
curl ’http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest'|\
grep ipv6 | grep CN | awk -F|
‘{ printf(“%s/%d\n”, $4, 32-log($5)/log(2)) }’ |
sed -e ‘s/^/add address=/g’ -e ‘s/$/ list=CNIP/g’|
sed -e $‘1i\\n/ipv6 firewall address-list’ \
-e $‘1i\\nremove [/ipv6 firewall address-list find list=CNIP]’|\
sed ‘$a /file remove CNIPv6.rsc’>CNIPv6.rsc
curl ’http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest'|\
grep ipv4 | grep CN | awk -F|
‘{ printf(“%s/%d\n”, $4, 32-log($5)/log(2)) }’ |\
sed -e ‘s/^/add address=/g’ -e ‘s/$/ list=CNIP/g’ \
-e ‘s/$/ comment=“CNIP”/g’ |\
sed -e $‘1i\\n/ip firewall address-list’ \
-e $‘1i\\nremove [/ip firewall address-list find list=CNIP]’ |\
sed ‘$a /’ |sed ‘$a /file remove CNIPv4.rsc’>CNIPv4.rsc
/ip firewall address-list
add list=CNIP address=x.x.x.x/xx
add list=CNIP address=x.x.x.x/xx
add list=CNIP address=x.x.x.x/xx
/ip/firewall/address-list/add name=proxy address=192.168.1.1-192.168.1.200
> 我们将 IP 地址范围 192.168.1.1--192.168.1.200 添加到代理列表中。
### (4)。 Mangle 非 CN IP 连接标记非CN IP目的地址```
add action=mark-routing chain=prerouting comment="ProxyRoute" \
src-address=proxy dst-address=!CNIP dst-address-type=!local \
new-routing-mark=OP passthrough=yes
添加另一条规则以接受openwrt的流量```
add action=accept chain=prerouting comment=“BypassOP”
src-address=192.168.1.254
> 假设openwrt的本地ip是`192.168.1.254`
### (5)。配置路由表配置到openwrt的路由表:```
/ip/route/add dst-address=0.0.0.0 gateway=192.168.1.254 \
check-getway=ping routing-table=OP distance=1 \
/interface/pppoe-client/set pppoe-CMCC default-route-distance=2
## 4. 如果绕过路由器关闭,则更改分配### (1).目的- openwrt down时的关闭分配- openwrt启动时开启分配
/tool/netwatch/add host=192.168.1.254 type=simple interval=60 \
up-script=OPUP.rsc down-script=OPDOWN.rsc
add dont-require-permissions=yes name=OPUP.rsc owner=admin policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=“/
ip firewall mangle enable number=???\r
\n/ip firewall mangle enable number=???\r
\n/ip route enable number=0\r
\n/ip/dns/cache/flush”
add dont-require-permissions=yes name=OPDOWN.rsc owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="/\
ip firewall mangle disable number=???\r\
\n/ip firewall mangle disable number=???\r\
\n/ip route disable number=0\r\
???是[MangleRules]中设置的mangle规则的索引号
[2]. https://idndx.com/high-availability-when-split-routing-using-routeros-and-raspberrypi/
[3]. 使用 SmartDNS 进行 DNS 分配
[4]. IPv6-在 Mikrotik-RouterOS-v7.x 上配置
[Clang.CN]:https://ispip.clang.cn/all_cn_cidr.txt[IPIP]:https://github.com/17mon/china_ip_list[RealIP数据库]:https://github.com/metowolf/iplist[MangleRules]:基于 RouterOS 和 Openwrt.md#4-mangle-non-cn-ip-connections 的 IP 地址列表分发