Skip to content

Instantly share code, notes, and snippets.

@goxofy
Last active October 20, 2017 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goxofy/1c6348cbac795e8d7a2bf6730d5deeaf to your computer and use it in GitHub Desktop.
Save goxofy/1c6348cbac795e8d7a2bf6730d5deeaf to your computer and use it in GitHub Desktop.
#/bin/bash
server_IP=123.45.67.89
[ -r chnroute.txt ] || 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)) }' > chnroute.txt
sudo iptables -t nat -N SHADOWSOCKS
sudo iptables -t nat -A PREROUTING -s 10.8.0.0/24 -p tcp -j SHADOWSOCKS
sudo iptables -t nat -A PREROUTING -s 10.8.0.0/24 -p udp -j SHADOWSOCKS
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A SHADOWSOCKS -d $server_IP -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
sudo ipset create chnroute hash:net
cat chnroute.txt | sudo xargs -I ip ipset add chnroute ip
sudo iptables -t nat -A SHADOWSOCKS -m set --match-set chnroute dst -j RETURN
sudo iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 1091
sudo iptables -t nat -A SHADOWSOCKS -p udp -j REDIRECT --to-ports 1091
#1091为ss-redir监听端口
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment