Skip to content

Instantly share code, notes, and snippets.

@jschpp
Last active April 25, 2020 03:29
Show Gist options
  • Save jschpp/d882e83f6fa3d8201ce3 to your computer and use it in GitHub Desktop.
Save jschpp/d882e83f6fa3d8201ce3 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