Skip to content

Instantly share code, notes, and snippets.

@lmlsna
Created August 6, 2018 00:44
Show Gist options
  • Save lmlsna/442bba9aad729c80c55dffe3a4612502 to your computer and use it in GitHub Desktop.
Save lmlsna/442bba9aad729c80c55dffe3a4612502 to your computer and use it in GitHub Desktop.
Allow fresh cloudflare IPs via iptables
#!/bin/bash
iptables -A INPUT -p tcp -m multiport --dports 80,443 -s $(curl -sSL --tlsv1.2 'https://www.cloudflare.com/ips-v4' | xargs | sed 's/ /,/g') -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 80,443 -j REJECT --reject-with tcp-reset
ip6tables -A INPUT -p tcp -m multiport --dports 80,443 -s $(curl -sSL --tlsv1.2 'https://www.cloudflare.com/ips-v6' | xargs | sed 's/ /,/g') -j ACCEPT
ip6tables -A INPUT -p tcp -m multiport --dports 80,443 -j REJECT --reject-with tcp-reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment