Skip to content

Instantly share code, notes, and snippets.

@lmlsna
Created November 27, 2017 18:30
Show Gist options
  • Save lmlsna/0fe2f8d3e0eb61c237ea44ba0d598317 to your computer and use it in GitHub Desktop.
Save lmlsna/0fe2f8d3e0eb61c237ea44ba0d598317 to your computer and use it in GitHub Desktop.
A Bash one-liner to whitelist Cloudflare's IPs in iptables.
#!/bin/bash
iptables -A INPUT -p tcp -m multiport --dports 80,443 -s $(for ip in $(curl -s https://www.cloudflare.com/ips-v4); do echo -n "$ip,"; done|head -c-1) -j ACCEPT
ip6tables -A INPUT -p tcp -m multiport --dports 80,443 -s $(for ip in $(curl -s https://www.cloudflare.com/ips-v6); do echo -n "$ip,"; done|head -c-1) -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment