Last active
February 24, 2024 15:03
-
-
Save sportshead/98f59af0cd20a54d875d9841ebcd6884 to your computer and use it in GitHub Desktop.
Automatically allow Cloudflare IPs in UFW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# simple script to fetch cloudflare IPs and allow them in UFW | |
# inspired by https://github.com/Paul-Reed/cloudflare-ufw | |
UFW="/usr/sbin/ufw" | |
DIR="$HOME/cf-ufw" | |
rm $DIR/ips.old | |
mv $DIR/ips $DIR/ips.old | |
curl -sw '\n' https://www.cloudflare.com/ips-v{4,6}/ > $DIR/ips | |
# print diff if changed, will be emailed by cron | |
git diff --no-index --no-renames $DIR/ips.old $DIR/ips | |
while read ip; do $UFW delete allow proto tcp from "$ip" to any port 80,443 comment 'Cloudflare' > /dev/null; done < $DIR/ips.old | |
while read ip; do $UFW allow proto tcp from "$ip" to any port 80,443 comment 'Cloudflare' > /dev/null; done < $DIR/ips | |
$UFW reload > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment