Skip to content

Instantly share code, notes, and snippets.

@haywardgg
Last active May 25, 2021 13:55
Show Gist options
  • Save haywardgg/42b674288c023dfe0c5a3a710ac4acd6 to your computer and use it in GitHub Desktop.
Save haywardgg/42b674288c023dfe0c5a3a710ac4acd6 to your computer and use it in GitHub Desktop.
Add CloudFlare IP Range to UFW using Bash!
At the command prompt type:
wget https://www.cloudflare.com/ips-v4
wget https://www.cloudflare.com/ips-v6
You should now have two files called ips-v4 and ips-v6
Next:
Create a file, call it whatever you like (i.e addcloudflare.s)
Cut and paste the following lines into the new file and save it.
# Cut/Copy from here -
while read -r line; do
ufw allow from "$line" to any port 80;
ufw allow from "$line" to any port 443;
done < ips-v4
while read -r line; do
ufw allow from "$line" to any port 80;
ufw allow from "$line" to any port 443;
done < ips-v6
# Cut/Copy above this line.
At the command prompt type:
chmod +x filename.s
sudo ./filename.s
WARNING: If this is the first time you've used UFW on your server, don't forget to open the port for SSH.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment