Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Created September 6, 2020 14:21
Show Gist options
  • Save rojenzaman/80d4f8f0aa34180efc17c0150f1b6dfa to your computer and use it in GitHub Desktop.
Save rojenzaman/80d4f8f0aa34180efc17c0150f1b6dfa to your computer and use it in GitHub Desktop.
firewalld rules for cloudflare cdn IPs (Red Hat, CentOS, Fedora)
#!/bin/bash
curl https://www.cloudflare.com/ips-v4 > .ips-v4
curl https://www.cloudflare.com/ips-v6 > .ips-v6
firewall-cmd --new-zone=cloudflare --permanent
firewall-cmd --reload
for i in `<.ips-v4`; do firewall-cmd --zone=cloudflare --add-source=$i; done
for i in `<.ips-v6`; do firewall-cmd --zone=cloudflare --add-source=$i; done
firewall-cmd --zone=cloudflare --add-port=80/tcp
firewall-cmd --zone=cloudflare --add-port=443/tcp
@DayZAnder
Copy link

Cloudflare has changed the way https://www.cloudflare.com/ips-v4 and https://www.cloudflare.com/ips-v6 works, redirecting to https://www.cloudflare.com/ips-v4/ and https://www.cloudflare.com/ips-v4/

Adjust your curl commands to

curl -L https://www.cloudflare.com/ips-v4 > .ips-v4
curl -L https://www.cloudflare.com/ips-v6 > .ips-v6

or use the url with trailing slash.
Cloudflare may or may update this, we'll see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment