Skip to content

Instantly share code, notes, and snippets.

@defclass
Created August 16, 2019 03:20
Show Gist options
  • Save defclass/69af437f8ff7a266ad2c2fd001b23703 to your computer and use it in GitHub Desktop.
Save defclass/69af437f8ff7a266ad2c2fd001b23703 to your computer and use it in GitHub Desktop.
/etc/iptables/redsocks.rules
# Transparent SOCKS proxy
# See: http://darkk.net.ru/redsocks/
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:REDSOCKS - [0:0]
# Redirect all output through redsocks
-A OUTPUT -p tcp -j REDSOCKS
# Whitelist LANs and some other reserved addresses.
# https://en.wikipedia.org/wiki/Reserved_IP_addresses#Reserved_IPv4_addresses
-A REDSOCKS -d 0.0.0.0/8 -j RETURN
-A REDSOCKS -d 10.0.0.0/8 -j RETURN
-A REDSOCKS -d 127.0.0.0/8 -j RETURN
-A REDSOCKS -d 169.254.0.0/16 -j RETURN
-A REDSOCKS -d 172.16.0.0/12 -j RETURN
-A REDSOCKS -d 192.168.0.0/16 -j RETURN
-A REDSOCKS -d 224.0.0.0/4 -j RETURN
-A REDSOCKS -d 240.0.0.0/4 -j RETURN
# import shadowsocks server ip
#-A REDSOCKS -d xxx.xxx.xxx.xxx -j RETURN
# shadowsocks server port
-A REDSOCKS -p tcp --dport xxxxx -j RETURN
# Redirect everything else to redsocks port
-A REDSOCKS -p tcp -j REDIRECT --to-ports 31338
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment