
Script per implementare Q-Feeds direttamente su NFtables o IPtables
Blocklist automatizzata di IP malware per server Linux — supporta nftables e iptables+ipset
Ottieni una chiave API gratuita su tip.qfeeds.com.
git clone https://github.com/Q-Feeds/NFtables-IPtables-integration-script.git
cd NFtables-IPtables-integration-script
chmod +x qfeeds-installer.sh qfeeds-uninstaller.sh
sudo ./qfeeds-installer.sh
L'installer:
Il tuo server è ora protetto. Il cron job controlla gli aggiornamenti ogni 20 minuti (configurabile), e le chiamate API effettive avvengono solo quando la tua licenza lo consente.
Questa soluzione scarica periodicamente il feed di threat intelligence più recente da Q-Feeds e lo applica come regole firewall (guida passo-passo: Configurazione NFtables/IPtables), permettendoti di:
L'installer rileva automaticamente quale backend firewall è disponibile:
| Priorità | Rilevamento | Backend |
|---|---|---|
| 1ª | comando nft trovato | nftables |
| 2ª | comando iptables trovato | iptables+ipset |
| — | Nessuno trovato | Errore (uscita) |
Il backend rilevato viene memorizzato nel file di configurazione. Gli script di aggiornamento e disinstallazione lo usano per eseguire i comandi firewall corretti.
Entrambi i backend usano la stessa strategia di set suddivisi per massime prestazioni:
Backend nftables:
┌─────────────────────────────────────────────────────────┐
│ table ip qfeeds │
│ │
│ ┌─────────────────────────┐ ┌───────────────────────┐ │
│ │ qfeeds_blacklist_v4 │ │ qfeeds_blacklist_v4 │ │
│ │ (hash set) │ │ _nets (interval set) │ │
│ │ │ │ │ │
│ │ Individual IPs │ │ CIDR ranges │ │
│ │ ~99% of entries │ │ ~1% of entries │ │
│ │ O(1) lookup & insert │ │ O(log n) lookup │ │
│ └─────────────────────────┘ └───────────────────────┘ │
│ │
│ ┌─────────────────────────┐ │
│ │ qfeeds_whitelist_v4 │ │
│ │ (interval set) │ │
│ │ Your allowed IPs/CIDRs │ │
│ └─────────────────────────┘ │
│ │
│ chain input-chain (hook input, priority 0, accept) │
│ → ip saddr @qfeeds_whitelist_v4 accept │
│ → ip saddr @qfeeds_blacklist_v4 drop │
│ → ip saddr @qfeeds_blacklist_v4_nets drop │
│ │
│ chain output-chain (if enabled) │
│ → ip daddr @qfeeds_whitelist_v4 accept │
│ → ip daddr @qfeeds_blacklist_v4 drop │
│ → ip daddr @qfeeds_blacklist_v4_nets drop │
└─────────────────────────────────────────────────────────┘
Backend iptables+ipset:
┌──────────────────────────────────────────────────────────┐
│ ipset sets │
│ │
│ ┌─────────────────────────┐ ┌────────────────────────┐ │
│ │ qfeeds_blacklist_v4 │ │ qfeeds_blacklist_v4 │ │
│ │ (hash:ip) │ │ _nets (hash:net) │ │
│ │ maxelem 1000000 │ │ maxelem 65536 │ │
│ │ │ │ │ │
│ │ Individual IPs │ │ CIDR ranges │ │
│ └─────────────────────────┘ └────────────────────────┘ │
│ │
│ ┌─────────────────────────┐ │
│ │ qfeeds_whitelist_v4 │ │
│ │ (hash:net) │ │
│ └─────────────────────────┘ │
│ │
│ iptables: INPUT/OUTPUT jump to a dedicated chain │
│ (jump rule tagged -m comment "qfeeds"): │
│ │
│ chain QFEEDS_INPUT (rebuilt each run, in order): │
│ -m set --match-set whitelist_v4 src -j ACCEPT │
│ -m set --match-set blacklist_v4 src -j DROP │
│ -m set --match-set blacklist_v4_nets src -j DROP │
│ (QFEEDS_OUTPUT mirrors this with dst, if enabled) │
└──────────────────────────────────────────────────────────┘
La stessa struttura esiste per IPv6 (tabella ip6 qfeeds o ip6tables + ipsets con family inet6).
Perché due tipi di set?