iptables-http-cloudflare 861 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # Check for root user
  3. CURR_USER=`/usr/bin/whoami`
  4. if [ "$CURR_USER" != "root" ]; then
  5. echo "I need root rights... Please login from root"
  6. exit
  7. fi
  8. # Clear rules
  9. /usr/local/bin/iptables-http-clear
  10. # Download IP list to temp file
  11. /usr/bin/wget "https://www.cloudflare.com/ips-v4" -O /tmp/ipslist.txt
  12. # Deny all requests to port 80 from all
  13. /sbin/iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 80 -j REJECT --reject-with tcp-reset
  14. # Allow requests from www.cloudflare.com
  15. while read ip; do
  16. if [ "$ip" != "" ]; then
  17. /sbin/iptables -I INPUT -p tcp -s $ip --dport 80 -j ACCEPT
  18. fi
  19. done < /tmp/ipslist.txt
  20. # Allow from our servers
  21. # /sbin/iptables -I INPUT -p tcp -s 127.0.0.1 --dport 80 -j ACCEPT
  22. # /sbin/iptables -I INPUT -p tcp -s 127.0.0.2 --dport 80 -j ACCEPT
  23. # Where "127.0.0.1" is our server IP
  24. # Remove temp file
  25. /bin/rm /tmp/ipslist.txt