Skip to content

Instantly share code, notes, and snippets.

@akyoto
Last active September 5, 2019 11:05
Show Gist options
  • Save akyoto/116e92fecf9bc87d1d2ea050d48345e1 to your computer and use it in GitHub Desktop.
Save akyoto/116e92fecf9bc87d1d2ea050d48345e1 to your computer and use it in GitHub Desktop.
iptables port forwarding
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -t raw -F
sudo iptables -t raw -X
sudo iptables -t security -F
sudo iptables -t security -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo ip6tables -F
sudo ip6tables -X
sudo ip6tables -t nat -F
sudo ip6tables -t nat -X
sudo ip6tables -t mangle -F
sudo ip6tables -t mangle -X
sudo ip6tables -t raw -F
sudo ip6tables -t raw -X
sudo ip6tables -t security -F
sudo ip6tables -t security -X
sudo ip6tables -P INPUT ACCEPT
sudo ip6tables -P FORWARD ACCEPT
sudo ip6tables -P OUTPUT ACCEPT
# Local testing
sudo iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 4000
sudo iptables -t nat -A OUTPUT -o lo -p tcp --dport 443 -j REDIRECT --to-port 4001
sudo ip6tables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 4000
sudo ip6tables -t nat -A OUTPUT -o lo -p tcp --dport 443 -j REDIRECT --to-port 4001
# Production
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 4000
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 4001
sudo ip6tables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 4000
sudo ip6tables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 4001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment