Skip to content

Instantly share code, notes, and snippets.

@kpodp0ra
Last active March 12, 2022 18:53
Show Gist options
  • Save kpodp0ra/b67b050558067a4bd36fd12561007aa3 to your computer and use it in GitHub Desktop.
Save kpodp0ra/b67b050558067a4bd36fd12561007aa3 to your computer and use it in GitHub Desktop.
Bash script for whitelisting cloudflare ips as well as setting nginx config to show real ips. Forked from: https://github.com/oasisfleeting/cloudflare-whitelister-nginx-real-ip
#!/bin/bash
echo "#Cloudflare" > /etc/nginx/conf.d/00_real_ip_cloudflare_00.conf;
iptables -D INPUT -j cloudflare;
iptables -F cloudflare;
iptables -X cloudflare;
iptables -N cloudflare;
for i in `curl https://www.cloudflare.com/ips-v4`; do
iptables -A cloudflare -p tcp -m multiport --dports http,https -s $i -j ACCEPT;
echo "set_real_ip_from $i;" >> /etc/nginx/conf.d/00_real_ip_cloudflare_00.conf;
done
iptables -A cloudflare -p tcp -m multiport --dports http,https -j DROP
iptables -A INPUT -j cloudflare;
echo "real_ip_header CF-Connecting-IP;" >> /etc/nginx/conf.d/00_real_ip_cloudflare_00.conf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment