Skip to content

Instantly share code, notes, and snippets.

@mcmoe
Last active November 27, 2018 13:07
Show Gist options
  • Save mcmoe/723d0a67ce8d54251442197269866f8a to your computer and use it in GitHub Desktop.
Save mcmoe/723d0a67ce8d54251442197269866f8a to your computer and use it in GitHub Desktop.
How to set up iptables in Linux using redsocks
Sources:

Checking redsocks service and config
cat /lib/systemd/system/redsocks.service
cat /etc/redsocks.conf
Setup iptables:
sudo iptables -t nat -N REDSOCKS

sudo iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

sudo iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345
Use redsocks chain for all the outgoing traffic
sudo iptables -t nat -A OUTPUT -p tcp -j REDSOCKS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment