Skip to content

Instantly share code, notes, and snippets.

@s00d
Forked from Manouchehri/cloudflare.sh
Last active October 4, 2019 13:50
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 s00d/9766402e1d0fcdef46e922cb8dfd663c to your computer and use it in GitHub Desktop.
Save s00d/9766402e1d0fcdef46e922cb8dfd663c to your computer and use it in GitHub Desktop.
Allow CloudFlare only
# Source:
# https://www.cloudflare.com/ips
# https://support.cloudflare.com/hc/en-us/articles/200169166-How-do-I-whitelist-CloudFlare-s-IP-addresses-in-iptables-
# Backup/Restore
# iptables-save > savedrules.txt
# cat savedrules.txt
# iptables-restore < savedrules.txt
for i in `curl https://www.cloudflare.com/ips-v4`; do iptables -I INPUT -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
for i in `curl https://www.cloudflare.com/ips-v6`; do ip6tables -I INPUT -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
# Avoid racking up billing/attacks
# WARNING: If you get attacked and CloudFlare drops you, your site(s) will be unreachable.
iptables -A INPUT -p tcp -m multiport --dports http,https -j DROP
ip6tables -A INPUT -p tcp -m multiport --dports http,https -j DROP
# chmod +x cloudflare.sh
# sh cloudflare.sh || bash cloudflare.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment