Skip to content

Instantly share code, notes, and snippets.

@sonnygauran
Created May 20, 2017 08:06
Show Gist options
  • Save sonnygauran/0673ad46bf296d6a65c325981e4d18f0 to your computer and use it in GitHub Desktop.
Save sonnygauran/0673ad46bf296d6a65c325981e4d18f0 to your computer and use it in GitHub Desktop.
Import IP v4 and v6 addresses from cloudflare
#!/bin/sh
DIR="$(dirname $(readlink -f $0))"
cd $DIR
wget https://www.cloudflare.com/ips-v4 -O ips-v4.tmp
wget https://www.cloudflare.com/ips-v6 -O ips-v6.tmp
mv ips-v4.tmp ips-v4
mv ips-v6.tmp ips-v6
for cfip in `cat ips-v4`; do ufw allow from $cfip; done
for cfip in `cat ips-v6`; do ufw allow from $cfip; done
ufw reload > /dev/null
# OTHER EXAMPLE RULES
# Examples to retrict to port 80
#for cfip in `cat ips-v4`; do ufw allow from $cfip to any port 80 proto tcp; done
#for cfip in `cat ips-v6`; do ufw allow from $cfip to any port 80 proto tcp; done
# Examples to restrict to port 443
#for cfip in `cat ips-v4`; do ufw allow from $cfip to any port 443 proto tcp; done
#for cfip in `cat ips-v6`; do ufw allow from $cfip to any port 443 proto tcp; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment