Skip to content

Instantly share code, notes, and snippets.

@pankpan
Created May 3, 2021 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pankpan/3d22c0e1311ef06366ba04903543674f to your computer and use it in GitHub Desktop.
Save pankpan/3d22c0e1311ef06366ba04903543674f to your computer and use it in GitHub Desktop.
iptables security policy for Cloudflare
#!/bin/bash
iptables -F
iptables -P INPUT DROP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
for IP in `curl -s https://www.cloudflare.com/ips-v4`
do
iptables -A INPUT -s $IP -p tcp -m multiport --dport 80,443 -j ACCEPT
done
# IPv6
ip6tables -F
ip6tables -P INPUT DROP
ip6tables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
for IP in `curl -s https://www.cloudflare.com/ips-v6`
do
ip6tables -A INPUT -s $IP -p tcp -m multiport --dport 80,443 -j ACCEPT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment