Created
April 26, 2019 04:55
-
-
Save lewangdev/603d6df73ed95dea94fd5cff2c82a5f6 to your computer and use it in GitHub Desktop.
create a transparency proxy on linux based router
This file contains hidden or 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
## IPSET | |
# OR ipset create gfwlist hash:ip | |
ipset -N gfwlist iphash | |
## DNS | |
# gwflist 中的域名转发 dns 请求到 1.1.1.1:53 查询,并且通过 dnsmasq 存到 gfwlist ipset 中 | |
# 启动一个本地 socks 代理给转发 DNS 使用 | |
/opt/shadowsocks/bin/ss-local -c /opt/shadowsocks/etc/dns2socks.conf -f /var/run/ss-local.pid | |
# https://github.com/qiuzi/dns2socks | |
# gcc -g -Wall -fPIC -c DNS2SOCKS.c -lpthread | |
# gcc DNS2SOCKS.o -o dns2socks -lpthread | |
nohup /opt/shadowsocks/bin/dns2socks 127.0.0.1:1082 1.1.1.1:53 127.0.0.1:15353 & | |
# https://raw.githubusercontent.com/hq450/fancyss/master/rules/gfwlist.conf | |
sed -i 's/7913/15353/g' /opt/shadowsocks/etc/gfwlist.conf | |
ln -s /opt/shadowsocks/etc/gfwlist.conf /etc/dnsmasq.d/gfwlist.conf | |
systemctl restart dnsmasq | |
## NAT | |
# 在 nat 表中创建链 | |
iptables -t nat -N GFWLIST | |
iptables -t nat -N SHADOWSOCKS | |
# 所有的 tcp 都转发到 SHADOWSOCKS | |
iptables -t nat -I PREROUTING 1 -p tcp -j SHADOWSOCKS | |
# 跳过一些不需要转发的 IP,如本地 IP,局域网 IP,组播 IP等特殊用途的 IP | |
iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN | |
iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN | |
iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN | |
iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN | |
iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN | |
iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN | |
# 跳过 SS 服务器 IP | |
iptables -t nat -A SHADOWSOCKS -d <SS Server IP> -j RETURN | |
# 剩下的 IP 到转发到 GFWLIST 进行检查 | |
iptables -t nat -A SHADOWSOCKS -p tcp -j GFWLIST | |
# 如果 IP 在 gfwlist 中,则转发到端口 1081 | |
iptables -t nat -A GFWLIST -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-port 1081 | |
# SS 在 1081 端口监听 | |
/opt/shadowsocks/bin/ss-redir -c /opt/shadowsocks/etc/ss.conf -f /var/run/ss-redir.pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment