#!/bin/sh /etc/rc.common # Example script # Copyright (C) 2007 OpenWrt.org USE_PROCD=1 START=99 getconfig(){ clashdir=/etc/clash ccfg=$clashdir/mark if [ ! -f "$ccfg" ]; then echo mark文件不存在,默认以Redir模式运行! cat >$ccfg< /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 #ip6tables -t nat -A PREROUTING -p tcp $ports-j REDIRECT --to-ports 7892 > /dev/null 2>&1 ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 } start_tun(){ #允许tun网卡接受流量 iptables -I FORWARD -o utun -j ACCEPT } start_service() { getconfig modifyyaml #创建clash后台进程 procd_open_instance procd_set_param respawn procd_set_param stderr 1 procd_set_param stdout 1 procd_set_param command $clashdir/clash -d $clashdir procd_close_instance #修改iptables规则使流量进入clash stop_redir start_tun start_redir mark_time } stop_service() { stop_redir }