Skip to content

Instantly share code, notes, and snippets.

@tojo17
Created August 2, 2018 15:06
Show Gist options
  • Save tojo17/46cda174e9de74be5451976fa8b9fd59 to your computer and use it in GitHub Desktop.
Save tojo17/46cda174e9de74be5451976fa8b9fd59 to your computer and use it in GitHub Desktop.
make switch great again
#!/bin/bash
# SS-REDIR TCP
iptables -t nat -N SSREDIR_TCP
# Bypass ssserver and LAN
iptables -t nat -A SSREDIR_TCP -d ===server ip=== -j RETURN
iptables -t nat -A SSREDIR_TCP -d 0.0.0.0/8 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 10.0.0.0/8 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 127.0.0.0/8 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 169.254.0.0/16 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 172.16.0.0/12 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 192.168.0.0/16 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 224.0.0.0/4 -j RETURN
iptables -t nat -A SSREDIR_TCP -d 240.0.0.0/4 -j RETURN
# Redirect TCP
iptables -t nat -A SSREDIR_TCP -p tcp -j REDIRECT --to-ports 1080
iptables -t nat -A PREROUTING -p tcp -j SSREDIR_TCP
# SS_REDIR UDP
ip rule add fwmark 0x02/0x02 table 100
ip route add local 0.0.0.0/0 dev lo table 100
iptables -t mangle -N SSREDIR_UDP
iptables -t mangle -A SSREDIR_UDP -d ===server ip=== -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A SSREDIR_UDP -d 240.0.0.0/4 -j RETURN
# Redirect UDP
iptables -t mangle -A SSREDIR_UDP -p udp -j TPROXY --on-port 1080 --tproxy-mark 0x02/0x02
# Enable
iptables -t mangle -A PREROUTING -j SSREDIR_UDP
nohup sudo /usr/local/bin/ss-redir -c /etc/shadowsocks.json -u > /dev/null 2>&1 &
sudo /opt/ss-redir/iptables.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment