Files
ShellCrash/clash/clashservice
juewuy e7858e8b63 1.合并Tun和Redir模式为一套文件,可以通过管理脚本直接切换
2.同步官方最新premium版核心,支持SSR
3.优化脚本可用性,增加了部分实用功能
2020-07-26 21:21:47 +08:00

64 lines
1.9 KiB
Bash

#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
USE_PROCD=1
START=99
start_redir(){
#修改iptables规则使流量进入clash
iptables -t nat -N clash
iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 127.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 169.254.0.0/16 -j RETURN
iptables -t nat -A clash -d 172.16.0.0/12 -j RETURN
iptables -t nat -A clash -d 192.168.0.0/16 -j RETURN
iptables -t nat -A clash -d 224.0.0.0/4 -j RETURN
iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN
iptables -t nat -A clash -p tcp -j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_redir(){
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
iptables -t nat -F clash > /dev/null 2>&1
iptables -t nat -X clash > /dev/null 2>&1
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
}
start_tun(){
#修改iptables规则使流量进入clash
iptables -I FORWARD -o utun -j ACCEPT
iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_tun(){
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
}
start_service() {
#创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param command /etc/clash/clash -d /etc/clash
procd_close_instance
#修改iptables规则使流量进入clash
Mod=`cat /bin/clash | grep 'Mark3=' -m1`
result=$(echo $Mod | grep "Tun模式")
if [[ "$result" != "" ]];then
stop_tun
start_tun
else
stop_redir
start_redir
fi
}
stop_service() {
Mod=`cat /bin/clash | grep 'Mark3=' -m1`
result=$(echo $Mod | grep "Tun模式")
if [[ "$result" != "" ]];then
stop_tun
else
stop_redir
fi
}