
نص برمجي لتنفيذ Q-Feeds مباشرة على NFtables أو IPtables
قائمة حظر عناوين IP للبرمجيات الخبيثة الآلية لخوادم Linux — تدعم nftables و iptables+ipset
احصل على مفتاح API مجاني من 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
سيقوم المثبّت بما يلي:
خادمك محمي الآن. تتحقق مهمة cron من التحديثات كل 20 دقيقة (قابل للتكوين)، ولا تحدث استدعاءات API الفعلية إلا عندما يسمح ترخيصك بذلك.
يقوم هذا الحل بتنزيل أحدث موجز استخبارات التهديدات من Q-Feeds بشكل دوري وتطبيقه كقواعد لجدار الحماية (دليل خطوة بخطوة: إعداد NFtables/IPtables)، مما يتيح لك:
يكتشف المثبّت تلقائيًا واجهة جدار الحماية الخلفية المتاحة:
| الأولوية | الكشف | الواجهة الخلفية |
|---|---|---|
| الأولى | تم العثور على الأمر nft | nftables |
| الثانية | تم العثور على الأمر iptables | iptables+ipset |
| — | لم يتم العثور على أي منهما | خطأ (خروج) |
يتم تخزين الواجهة الخلفية المكتشفة في ملف التكوين. تستخدم سكربتات التحديث وإلغاء التثبيت هذه الواجهة لتشغيل أوامر جدار الحماية الصحيحة.
تستخدم كلتا الواجهتين الخلفيتين نفس استراتيجية المجموعات المنقسمة لأقصى أداء:
الواجهة الخلفية 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:
┌──────────────────────────────────────────────────────────┐
│ 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) │
└──────────────────────────────────────────────────────────┘
يوجد نفس البنية لعنوان IPv6 (جدول ip6 qfeeds أو ip6tables + ipsets مع family inet6).
لماذا نوعان من المجموعات؟
┌──────────────────────────────────────────────────────┐
│ 1. Check license schedule (licenses.php API) │
│ → Skip run if not yet time for next update │
│ 2. Determine sync mode (full or diff) │
│ 3. Fetch IPv4 feed (ipv6=0) and IPv6 feed │
│ (ipv6=only) separately │
│ 4. Separate IPs from CIDRs in awk │
│ 5. Batch-load into hash set (IPs) and net/interval │
│ set (CIDRs) │
│ 6. Update whitelist sets from config │
│ 7. Persist rules │
└──────────────────────────────────────────────────────┘