Files
ShellCrash/clash_redir_config/clashservice
2020-07-24 14:41:21 +08:00

37 lines
1.2 KiB
Bash

#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
USE_PROCD=1
START=99
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
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 198.18.0.1/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_service() {
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash
iptables -t nat -F clash
iptables -t nat -X clash
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}