-
Notifications
You must be signed in to change notification settings - Fork 0
Optimization Tools and Tweaks
Optional performance optimizations for NFTBan feed processing and large IP set management.
- Purpose
- CIDR Aggregation
- Supported Methods
- Setup
- Verification
- Distro Compatibility
- Health Reporting
- When to Enable
- Troubleshooting
- Design Philosophy
- References
NFTBan processes threat intelligence feeds and geographic IP lists that can contain hundreds of thousands of entries. Without optimization, these lists are loaded as-is into nftables interval sets, resulting in larger sets, higher memory usage, and slower kernel operations.
This page documents optional tools that reduce list sizes through CIDR aggregation. These tools are not required for normal operation. NFTBan always works without them using safe fallbacks.
CIDR aggregation merges overlapping and adjacent IP entries into compact CIDR blocks.
Before: 192.168.1.0/24, 192.168.1.128/25, 192.168.2.0/24
After: 192.168.1.0/24, 192.168.2.0/24
Before: 10.0.0.0/24, 10.0.1.0/24
After: 10.0.0.0/23
| Metric | Without Aggregation | With Aggregation |
|---|---|---|
| Set size (typical feed) | 500K entries | 50K-100K entries |
| nftables memory | Higher | Lower |
| Ban operation time (500K set) | ~25 seconds | ~5-10 seconds |
| Feed update time | Slower | Faster |
The kernel stores interval sets as red-black trees. Fewer entries = smaller tree = faster lookups and insertions.
NFTBan automatically selects the best available method. The fallback chain is:
Full CIDR aggregation for both IPv4 and IPv6. Handles merging, normalization, and overlap absorption.
# IPv4 example
echo -e "10.0.0.0/24\n10.0.1.0/24" | aggregate6 -4
# Output: 10.0.0.0/23
# IPv6 example
echo -e "2001:db8::/48\n2001:db8:1::/48\n2001:db8:2::/48\n2001:db8:3::/48" | aggregate6 -6
# Output: 2001:db8::/46- IPv4: Full support
- IPv6: Full support
-
Binary location:
/usr/local/bin/aggregate6
Native system package. Performs basic CIDR normalization for IPv4 only.
netmask -c < ip_list.txt | sort -u > merged.txt- IPv4: Supported
- IPv6: Not supported (IPv6 lists use bash fallback)
-
Package:
netmask(Debian, Ubuntu, AlmaLinux via EPEL)
Built-in fallback. Removes exact duplicates and contained CIDRs. Does not merge adjacent ranges.
- IPv4: Dedup only (no neighbor merge)
- IPv6: Dedup only
- Dependencies: None (built into NFTBan)
| Capability | aggregate6 | netmask | bash |
|---|---|---|---|
| IPv4 merge | Yes | Partial | No |
| IPv6 merge | Yes | No | No |
| Adjacent merge (10.0.0.0/24 + 10.0.1.0/24 = /23) | Yes | No | No |
| Overlap absorption | Yes | Partial | No |
| Duplicate removal | Yes | Yes | Yes |
| External dependency | Yes (pip3) | Yes (package) | None |
nftban statusThe output includes the active CIDR method.
Run the explicit setup command:
nftban update --setup-cidr-toolsThis command:
- Detects the Python version and distro
- Installs build prerequisites if needed (Python 3.12+ requires
gccandpython3-dev/python3-devel) - Installs aggregate6 via pip3
- Verifies the tool works with IPv4 and IPv6 test cases
- Falls back to netmask or bash if installation fails
The setup never modifies the firewall or interrupts protection.
For environments where the automated setup is not suitable:
# Python 3.12+ (Debian 13, Ubuntu 24.04, Rocky 10)
pip3 install py-radix-sr --break-system-packages
pip3 install aggregate6 --no-deps --break-system-packages
# Python 3.9-3.11 (AlmaLinux 9, RHEL 9)
pip3 install aggregate6Why two steps on Python 3.12+: The upstream py-radix C extension does not compile against Python 3.12+ headers. py-radix-sr is a maintained fork that fixes this. The --no-deps flag tells pip to use the already-installed fork instead of pulling the broken original.
| Distro | Python | Packages Needed |
|---|---|---|
| Debian 13 | 3.13 | python3-pip python3-dev gcc |
| Ubuntu 24.04 | 3.12 | python3-pip python3-dev gcc |
| Rocky 10 | 3.12 | python3-pip python3-devel gcc |
| AlmaLinux 9 | 3.9 |
python3-pip (no build tools needed) |
These are not installed automatically by the NFTBan package. They are build-time tools required only for setting up aggregate6.
After setup, verify the tool works:
# Check which tool is active
nftban status | grep -i cidr
# Test IPv4 aggregation
echo -e "10.0.0.0/24\n10.0.1.0/24" | aggregate6 -4
# Expected: 10.0.0.0/23
# Test IPv6 aggregation
echo -e "2001:db8::/48\n2001:db8:1::/48" | aggregate6 -6
# Expected: 2001:db8::/47| Distro | aggregate6 | netmask | bash | Notes |
|---|---|---|---|---|
| Debian 13 | Via pip3 (needs gcc) | apt install netmask |
Built-in | Full support |
| Ubuntu 24.04 | Via pip3 (needs gcc) | apt install netmask |
Built-in | Full support |
| Rocky 10 | Via pip3 (needs gcc) | Not available | Built-in | No netmask in repos |
| AlmaLinux 9 | Via pip3 (direct) |
dnf install netmask (EPEL) |
Built-in | Pre-built wheel |
Rocky 10 note: netmask is not available in any Rocky 10 repository. aggregate6 is the only CIDR optimization tool on this platform. If aggregate6 is not installed, NFTBan uses bash dedup.
NFTBan health checks report the active CIDR method.
| Condition | Level | Exit Code |
|---|---|---|
| aggregate6 active | OK | 0 |
| netmask active (IPv4 fallback) | INFO | 0 |
| bash fallback active | INFO | 0 |
| aggregate6 installed but broken | WARN | 1 |
Missing CIDR tools are reported as INFO, not ERROR. NFTBan is fully functional without them.
{
"health": {
"cidr_aggregation": {
"tool": "aggregate6",
"ipv4": true,
"ipv6": true,
"status": "protected"
}
}
}- Using threat intelligence feeds (
nftban feeds enable) - Using GeoBan for country-level blocking
- Managing more than 10,000 banned IPs
- Running frequent feed updates (hourly or more)
- Observing slow ban operations on loaded systems
- Manual bans only (fewer than 1,000 IPs)
- Testing or development environments
- No feeds or GeoBan configured
- System resources are not constrained
Check prerequisites:
# Debian/Ubuntu
dpkg -l python3-pip python3-dev gcc
# Rocky/Alma
rpm -q python3-pip python3-devel gccInstall any missing packages, then retry.
Verify the binary is in PATH:
which aggregate6
# Expected: /usr/local/bin/aggregate6If installed in a Python user directory, create a symlink:
ln -s ~/.local/bin/aggregate6 /usr/local/bin/aggregate6This is expected. The upstream py-radix package has a broken C extension on Python 3.12+.
Fix:
pip3 install py-radix-sr --break-system-packages
pip3 install aggregate6 --no-deps --break-system-packagesAggregation reduces overlapping and adjacent entries. If a feed contains dispersed individual IPs with no overlap, the reduction is minimal. This is normal.
Check actual reduction:
# View aggregation log entries
grep "CIDR merge" /var/log/nftban/nftban.logExample output:
CIDR merge (aggregate6): 500000 -> 48532 (merged 451468 overlaps)
NFTBan follows the principle: always work, optimize when available.
- The firewall never fails because an optimizer is missing
- Optimization tools are optional enhancements, not requirements
- The system adapts to the available environment
- Setup is an explicit admin action, not an implicit side effect of installation
Build tools (gcc, python3-dev) are never pulled automatically by the NFTBan package. They are installed on demand during explicit CIDR tool setup.
- Source:
cli/lib/nftban/lib/nftban_dataset_cidr.sh— CIDR merge implementation - Related: Performance Benchmarks — IPC and set performance data
- Related: NFT Schema Validation — nftables set definitions and
auto-merge - Related: Health Check Architecture — Health severity model
- Related: Supported Platforms — Distro compatibility matrix
- Related: Installation Guide — Core installation steps
NFTBan Wiki
Getting Started
Architecture
Modules
- BotGuard (HTTP L7)
- BotScan (Web Access-Log)
- DDoS Protection (L3/L4)
- Portscan Detection
- Login Monitoring
- Blacklist & Threat Intelligence
- Suricata IDS Integration
- DNS Tunnel Suspicion
Operator Reference
- CLI Commands Reference
- Configuration Reference
- Systemd Units & Timers
- Optimization & Tuning
- Security Operations Guide
- GeoIP Database Guide
- FHS Compliance
- Troubleshooting: Smoke & Selftest
Verification & Trust
- Glossary & Vocabulary
- Known Limitations
- Metrics & Evidence Model
- Binary Verification (SLSA)
- Security Architecture
Reference
Legal