-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the nft-rulesets wiki!
From my point of view a firewall should drop all traffic that is not explicitly allowed.
So I wanted to allow access to the resources that I host from only some countries and drop everything else. Unfortunately it's not granular enough to be accurate. Because we may also have to block some flows from compromised IP addresses or subnets, in countries that we granted access.
Here is how to proceed :
- Block a list of IP addresses or subnets using the netdev table functionnality
- Allow some countries IP subnets
- Block everything else.
And have separated policy for IPv4 and IPv4.
This script and all files provided tries to achieve this goal, unsing nftables. It is tested/developped on my Debian boxes, but I am pretty convinced that it ought to work on any linux flavour, as soon as you have access to the software that the script uses. As the script tests at the beginning if it finds and can access to all programs that it needs, it will tell you the reason why it can't eventually run on your server.
The goal of the script is to download the MaxMind GeoIP databases (IPv4 and IPv6) and compute all lists. Here is the several steps that this script is doing.
------------- [ Startup of the script. ]------------
---> [ STEP 01 Initial checks ]------------
---> [ STEP 02 Creation of a Temporary RamDrive to compute and download Files ]------------
---> [ STEP 03 Creation of a /tmp/RamDriveTemp and checks if script can write in ]------------
---> [ STEP 04 Download MaxMind Database ]------------
---> [ STEP 05 Compare SHA256 checksum of Downloaded database ]------------
---> [ STEP 06 Extracts the archive to RamDrive ]------------
---> [ STEP 07 Transform all files, Ordering and Filtering ]------------
---> [ STEP 08 Select list of countries ]------------
---> [ STEP 09 Insert commas and join lines of files located in RamDriveTemp. ]------------
-----> [ STEP 09a modify IPv4 files ]------------
-----> [ STEP 09b modify IPv6 files ]------------
---> [ STEP 10 Archive and Copy Files ]------------
---> [ STEP 11 RamDrive destruction ]------------
Script run time : 26s
nft-ruleset [-v] [-h] [-p] [-l q|f] [-s d|n]
-v : Version
-h : This help file
-p : Purge all stored backups
-l : Log Level
q : quiet, store only starting and ending in logfile
f : store full details in logfile
-s : Only run a small part of this script, options have to be mentioned
d : download : Only donwloads database and sha256 file
n : just add rulesets to nftables
-v : displays the version of the script
-h : Displays the help menu
-p : Purge all the archives previously stored
-l q : Quiet mode, this stores errors and all steps only in log file. -l f : Verbose mode, outputs each detailed steps
This still have to be implemented -d : Donwload only -n : Add the rules to firewall