Skip to content

Instantly share code, notes, and snippets.

@robsonsobral
Forked from jschpp/cloudflare-ip.sh
Created April 25, 2020 03:29
Show Gist options
  • Save robsonsobral/240e346bb75ba208fe47db0581932349 to your computer and use it in GitHub Desktop.
Save robsonsobral/240e346bb75ba208fe47db0581932349 to your computer and use it in GitHub Desktop.
script to add all cloudflare IPs to iptables
#!/bin/sh
exec > /var/log/cloudflare.log 2>&1
set -x
for ip in $(curl -s https://www.cloudflare.com/ips-v4); do /usr/sbin/iptables -I INPUT -p tcp -m multiport --dports http,https -s "$ip" -j ACCEPT; done
for ip in $(curl -s https://www.cloudflare.com/ips-v6); do /usr/sbin/ip6tables -I INPUT -p tcp -m multiport --dports http,https -s "$ip" -j ACCEPT; done
#!/bin/sh
[Unit]
Description=Add cloudflare ips to iptables
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/sh /usr/local/src/cloudflare-ip.sh
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment