Skip to content

Instantly share code, notes, and snippets.

@ramon-sg
Created November 4, 2019 17:34
Show Gist options
  • Save ramon-sg/b8e9bae816c1f24d9800ec7183674980 to your computer and use it in GitHub Desktop.
Save ramon-sg/b8e9bae816c1f24d9800ec7183674980 to your computer and use it in GitHub Desktop.
cat << 'EOF' >> redsocks.conf
base {
log_debug = off;
log_info = on;
log = "syslog:daemon";
daemon = on
user = redsocks;
group = redsocks;
redirector = iptables;
}
redsocks {
local_ip = 127.0.0.1;
local_port = 12345;
ip = 127.0.0.1;
port = 3128;
type = http-connect;
}
EOF
echo "Config redsocks..."
sudo mv /etc/redsocks.conf /etc/redsocks.conf.BACK
sudo cp redsocks.conf /etc/
echo "config iptables"
sudo iptables -t nat -N REDSOCKS
# Ignore LANs and some other reserved addresses.
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
# Anything else should be redirected to port 12345
sudo iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment