Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Created March 23, 2024 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RealYukiSan/98f3887b3347f00a396792e1e456b4e9 to your computer and use it in GitHub Desktop.
Save RealYukiSan/98f3887b3347f00a396792e1e456b4e9 to your computer and use it in GitHub Desktop.
iptables rules for redsocks
# 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
# Redirect everything else to redsocks port
-A REDSOCKS -p tcp -j REDIRECT --to-ports 31338
-A OUTPUT -p tcp --dport 443 -j REDSOCKS
-A OUTPUT -p tcp --dport 80 -j REDSOCKS
-A PREROUTING -p tcp --dport 443 -j REDSOCKS
-A PREROUTING -p tcp --dport 80 -j REDSOCKS
COMMIT
@RealYukiSan
Copy link
Author

The rules file only contains minor changes compared to the default rules provided by the redsocks package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment