Created
June 15, 2019 06:48
-
-
Save tony1016/6ff15945c207ec05d937284267e1a129 to your computer and use it in GitHub Desktop.
Openwrt init.d script for clash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
START=99 | |
STOP=15 | |
USE_PROCD=1 | |
start_service(){ | |
procd_open_instance clash | |
procd_set_param command /usr/bin/clash -d /etc/clash | |
#提前建立好clash的账户 | |
procd_set_param user clash | |
procd_close_instance | |
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 | |
#假设你的clash用clash这个用户运行起来了,则底下这两句可以让路由器自身也可以走clash | |
iptables -t nat -A OUTPUT -m owner --uid-owner clash -j RETURN | |
iptables -t nat -A OUTPUT -p tcp -j clash | |
} | |
stop_service(){ | |
iptables -t nat -D OUTPUT -p tcp -j clash | |
iptables -t nat -D OUTPUT -m owner --uid-owner clash -j RETURN | |
iptables -t nat -D PREROUTING -p tcp -j clash | |
iptables -t nat -F clash | |
iptables -t nat -X clash | |
killall clash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment