Last active
June 11, 2019 14:24
-
-
Save gadelkareem/fe552d70f9d58634a40f7a959700edbd to your computer and use it in GitHub Desktop.
Allow Cloudflare IPs on port 80 and 443 using UFW https://gadelkareem.com/2019/06/11/allow-cloudflare-ips-on-port-80-and-443-using-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
#!/usr/bin/env bash | |
set -euo pipefail | |
# lock it | |
PIDFILE="/tmp/$(basename "${BASH_SOURCE[0]%.*}.pid")" | |
exec 200>${PIDFILE} | |
flock -n 200 || ( echo "${BASH_SOURCE[0]} script is already running. Aborting . ." && exit 1 ) | |
PID=$$ | |
echo ${PID} 1>&200 | |
cd "$(dirname $(readlink -f "${BASH_SOURCE[0]}"))" | |
CUR_DIR="$(pwd)" | |
wget https://www.cloudflare.com/ips-v4 -O ips-v4 | |
wget https://www.cloudflare.com/ips-v6 -O ips-v6 | |
for cfip in `cat ips-v4`; do /usr/sbin/ufw allow from $cfip to any port 80,443 proto tcp comment "cloudflare"; done | |
for cfip in `cat ips-v6`; do /usr/sbin/ufw allow from $cfip to any port 80,443 proto tcp comment "cloudflare"; done | |
/usr/sbin/ufw reload > /dev/null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment