Git Product home page Git Product logo

cloudflare-ufw's Introduction

cloudflare-ufw

Script to update UFW with Cloudflare IPs

This script was kindly written by Leow Kah Man and I've added a few tweaks!

Setup

Assuming that you already have ufw installed (now a pre-installed package in most linux distros), firstly ensure that ufw is not enabled;

sudo ufw status verbose

If it's not enabled, the response should be Status: inactive but if not, let's disable it;

sudo ufw disable

Clear out any existing rules;

sudo ufw reset

and set the default rules to deny incoming and allow outgoing connections;

sudo ufw default deny incoming
sudo ufw default allow outgoing

It's important at this stage to prevent being accidently being locked out of your system by adding 2 rules, before going further.
Add a localhost rule;

sudo ufw allow from 192.168.1.0/24

and also allow SSH access;

sudo ufw allow ssh

Provided those rules were succesfully added, time to enable your firewall;

sudo ufw enable

You will receive a warning that says the "command may disrupt existing ssh connections." We have already set up a firewall rule that allows SSH connections so it should be fine to continue. Respond to the prompt with y.
You can run the sudo ufw status verbose command to see the rules that are set.

Install the script

Git clone this repo to your system, and run the bash script in the normal manner;

sudo /your/path/cloudflare-ufw/./cloudflare-ufw.sh

The script will then download Cloudflare's current v4 & v6 IP's, and install them into ufw's configuration. Check that the rules have been successfuly added; sudo ufw status verbose

Scheduling

Everytime the script is run, it will add any new Cloudflare IP addresses, so consider running the script weekly to ensure that it's kept up to date.
The script can run automatically by using cron;

sudo crontab -e

and add the event;

0 0 * * 1 /your/path/cloudflare-ufw/cloudflare-ufw.sh > /dev/null 2>&1

OR

If using node-red, simply add sudo /your/path/cloudflare-ufw/./cloudflare-ufw.sh to an 'exec node' and inject it every week.

cloudflare-ufw's People

Contributors

paul-reed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.