Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rgdev/89ac33fcc90b0eb4a8467904d50373dd to your computer and use it in GitHub Desktop.

Select an option

Save rgdev/89ac33fcc90b0eb4a8467904d50373dd to your computer and use it in GitHub Desktop.
A script to generate a config to allow or additionally allow cloudflare addresses for a specific domain
#!/bin/bash
set -e
cf_ips() {
echo "# https://www.cloudflare.com/ips"
for type in v4 v6; do
echo "# IP$type"
curl -s "https://www.cloudflare.com/ips-$type" | sed "s|^|allow |g" | sed "s|\$|;|g"
echo
done
echo "# internal"
echo "allow 127.0.0.0/8;"
echo "allow 192.168.0.0/16;"
echo "allow 10.0.0.0/8;"
echo "allow 172.16.0.0/12;"
echo
echo "# Generated at $(LC_ALL=C date)"
}
cf_ips > allow-cloudflare.conf
(cf_ips && echo "deny all; # deny all remaining ips") > cloudflare.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment