High-performance firewall and monitoring suite for Keenetic routers (Entware/NDM). This suite integrates massive IPSET blocklists, provides real-time traffic analysis, VPN protection, and a rich HTML dashboard with historical data and threat intelligence.
- Zero Performance Impact: Uses kernel
ipset(hash:net) to block 20,000+ IPs efficiently. - Fail-safe Boot: Smart loader restores the last known good blocklist if the internet is down at boot.
- Smart Updates: Daily updates with deduplication and "Zero Downtime" swapping.
- VPN Compatibility: Automatically handles VPN interfaces (
tun+) and excludes LAN traffic.
- Rich HTML Dashboard: Visualizes traffic with Chart.js (Hourly/Daily/Monthly stats).
- Threat Intelligence: Integrates AbuseIPDB API to identify and geolocate top threats.
- SQLite Backend: Stores historical data efficiently for long-term trend analysis.
- VPN Protection: Scans logs for OpenVPN brute-force attacks and bans attackers dynamically.
- Real-Time Terminal Monitor: A
top-like interface for your firewall to see dropped packets in real-time.
- Keenetic Router with Entware installed.
- Web Server (Optional but recommended): A web server (like
lighttpdornginx) running on Entware is required to view the HTML dashboards. - Dependencies: Install the following packages via SSH:
opkg update
opkg install ipset iptables bash wget-ssl curl \
sqlite3-cli coreutils-date mtr \
grep awk sedNote: coreutils-date is crucial for accurate timestamp calculations in the database scripts.
You can install the suite automatically using Keentool (recommended) or manually.
Use Keentool, the all-in-one manager, to install, update, and configure the Firewall Suite and its dependencies automatically.
- Run the following command in your SSH terminal:
curl -sL https://raw.githubusercontent.com/mattheweli/keentool/main/keentool -o /opt/bin/keentool && chmod +x /opt/bin/keentool && /opt/bin/keentool
- Select 3. Firewall Suite from the menu.
- Choose 1. Install / Update.
- The tool will automatically download scripts, set permissions, and configure Crontab.
- It will also guide you through setting up the AbuseIPDB Key.
If you prefer to configure everything yourself, follow these steps:
Handles the blocking logic and boot loading.
- Boot Loader: Copy
scripts/S00ipset-loadto/opt/etc/init.d/S00ipset-load. - Kernel Hook: Copy
scripts/100-firewall.shto/opt/etc/ndm/netfilter.d/100-firewall.sh. - Permissions:
chmod +x /opt/etc/init.d/S00ipset-load chmod +x /opt/etc/ndm/netfilter.d/100-firewall.sh
Keeps lists fresh and bans VPN attackers.
- Copy
scripts/update_blocklist.shto/opt/bin/update_blocklist.sh. - Copy
scripts/vpn_scan.shto/opt/bin/vpn_scan.sh. - Permissions:
chmod +x /opt/bin/update_blocklist.sh chmod +x /opt/bin/vpn_scan.sh
Generates the HTML dashboard.
- Copy
scripts/firewall_stats.shto/opt/bin/firewall_stats.sh. - Configuration: Edit the file and add your AbuseIPDB Key:
ABUSEIPDB_KEY="your_api_key_here" - Permissions:
chmod +x /opt/bin/firewall_stats.sh
Real-time stats in your SSH terminal.
- Copy
scripts/firewall_monitorto/opt/bin/firewall_monitor(no extension). - Permissions:
chmod +x /opt/bin/firewall_monitor
To make everything work automatically, add these lines to your crontab (/opt/etc/crontab):
# ๐ก๏ธ Firewall: Update Blocklists (Daily at 04:00)
0 4 * * * root /opt/bin/update_blocklist.sh > /dev/null 2>&1
# ๐ Stats: Generate Dashboard (Every hour at min 01)
1 * * * * root /opt/bin/firewall_stats.sh > /dev/null 2>&1
# ๐ต๏ธ VPN: Scan for attackers (Every 3 hours)
0 */3 * * * root /opt/bin/vpn_scan.sh > /dev/null 2>&1If you have a web server set up pointing to /opt/var/www/, access:
- Firewall Stats:
http://router-ip:port/firewall/
Simply run from your SSH terminal:
firewall_monitorShows real-time drops, session statistics, and the top 5 active blocked sources.
Run the manager at any time to check for updates or manage settings:
keentoolThe Firewall Manager (firewall_manager.sh) is the central control panel for the Keenetic Firewall Suite. It allows you to configure security modules, manage blacklists/whitelists, view real-time logs, and generate statistics without needing to edit configuration files manually.
To launch the manager, access your router via SSH and run:
/opt/bin/firewall_manager.shNote: Ensure you are running as
root. The script will automatically load your current configuration from/opt/etc/firewall.conf.
When you launch the manager, you will see the following options:
- 1) Show Live Monitor: Opens a real-time log viewer (
firewall_monitor) showing blocked packets. PressCtrl+Cto exit. - 3) Run Stats & Dashboard: Manually triggers the statistics engine (
firewall_stats.sh). This updates the database and the JSON files used by the Web Dashboard. Useful if you want to see immediate changes on the UI. - 5) Run Abuse Reporter: Manually triggers the reporting script to send recent attackers to AbuseIPDB (if API key is configured).
- 2) Update Blocklists: Downloads and refreshes the static IP blocklists (FirewallBlock) from the configured sources.
- 4) Run VPN Scan: Scans active VPN connections for blacklisted IPs and kicks them if found.
- 6) Run Diagnostics: Performs a system health check. It verifies if:
- ULOGD logger is running.
- Cron scheduler is active.
- Kernel modules (
xt_recent) are loaded. - IP Sets are populated (IPv4/IPv6).
- IPTables chains are correctly linked.
- 7) Restart Firewall Hook: Reloads the core firewall rules (
100-firewall.sh) and applies the current configuration. Use this after manual changes to.conffiles. - 9) Manage Whitelist: Opens the Whitelist Editor.
- f) Flush Lists: Opens the Flush Menu to clear specific lists immediately.
The Settings Menu (Option 8) allows you to toggle features and tune parameters on the fly.
- IPv6 Support: Toggles IPv6 firewall rules and blocklists.
- Forward Protection: If ON, the AutoBan trap applies to traffic passing through the router (e.g., to a NAS).
- Warning: Ensure your Whitelist is configured before enabling this to avoid blocking legitimate services.
- AutoBan (Dynamic): Toggles the "Honeypot" trap. If OFF, port scanners are logged but not banned.
- BruteForce Protection: Toggles the
xt_recentmodule to ban IPs attempting multiple connections in a short time. - DDoS ConnLimit: Limits the maximum simultaneous connections per source IP (Default: 15).
- Auto-Ban Timeout: Set how long an IP remains banned in the AutoBan list.
- Supports distinct values (e.g.,
3600) or0for Permanent Ban. - Feature: Changing this applies immediately without a full firewall restart.
- Supports distinct values (e.g.,
- Brute-Force Sensitivity: Configure the threshold for banning.
- Example: 5 hits in 60 seconds.
- Allowed Ports: Define which TCP/UDP ports are "Open" (Safe). Traffic to any port not in this list will trigger the AutoBan trap.
- AbuseIPDB Settings: Configure your API Key and set the Reporting Cooldown (default 7 days) to avoid spamming reports.
Accessed via Option 9. Use this to prevent you or your services from being blocked.
- Add Entry (a): Supports:
- Single IPs (
1.2.3.4) - Subnets/CIDR (
192.168.1.0/24) - Domains (
example.com) - Automatically resolves to both IPv4 and IPv6 IPs.
- Single IPs (
- Remove Entry (r): Delete a line from the whitelist.
- Apply (x): Crucial Step. Reloads the whitelist into the running firewall immediately.
Accessed via Option f. Use this if you accidentally banned yourself or need to clear lists.
- 1) AutoBan: Clears dynamic bans (Trap).
- 2) FirewallBlock: Clears downloaded static blocklists.
- 3) VPNBlock: Clears banned VPN IPs.
- 4) Whitelist: Clears the trusted list (use with caution).
- 9) FLUSH ALL: completely empties all IP sets.
While firewall_manager.sh is for manual control, the system relies on cron for automation.
Recommended crontab setup to avoid conflicts between updates and stats generation:
# Network Monitoring
*/1 * * * * root /opt/bin/pingtool.sh >> /opt/var/log/connmon.log 2>&1
# Stats Generation (Every 30 mins)
*/30 * * * * root /opt/bin/firewall_stats.sh > /dev/null 2>&1
# Blocklist Update (Once a day at 04:15 - Staggered to avoid conflict with stats)
15 4 * * * root /opt/bin/update_blocklist.sh > /dev/null 2>&1
# Security Scans
15 * * * * root /opt/bin/vpn_scan.sh > /dev/null 2>&1
45 * * * * root /opt/bin/abuse_reporter.sh > /dev/null 2>&1Designed for KeeneticOS routers running Entware.
