
Script per implementare Q-Feeds direttamente su NFtables o IPtables
Blocklist automatica 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
### Passaggio 3: Esegui l'installer come root```bash
sudo ./qfeeds-installer.sh
L'installer:
Il tuo server è ora protetto. Il job cron 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, 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 utilizzano per eseguire i comandi firewall corretti.
Entrambi i backend utilizzano la stessa strategia di set divisi per le 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 │ └─────────────────────────────────────────────────────────┘
**iptables+ipset backend:**```
┌──────────────────────────────────────────────────────────┐
│ 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 family inet6).
Perché due tipi di set?