تهيئة جدار حماية Linux باستخدام nftables
تحكّم في حركة المرور الواردة والصادرة على مضيف Linux باستخدام nftables وواجهة ufw السهلة لتأمين خدمات الشبكة.
تهيئة جدار حماية Linux باستخدام nftables درس مجاني في Linux Networking & TCP/IP for Developers على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Linux Networking & TCP/IP for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Linux Networking & TCP/IP for Developers 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why a Host Firewall?
A host firewall decides which packets are allowed in or out of a single machine. It is your last line of defense, protecting services even when the network perimeter is breached.
From iptables to nftables
Modern Linux uses nftables as the kernel packet-filtering framework, replacing the older iptables. It uses tables, chains, and rules but with a cleaner, unified syntax.
Tables, Chains, and Rules
In nftables a table holds chains, a chain holds ordered rules, and each rule matches packets and takes an action like accept or drop. Chains hook into traffic at points such as input and output.
Listing the Ruleset
See the entire active configuration with a single command. This is always your first step before changing anything.
sudo nft list rulesetA Simple Input Policy
Create a table and an input chain with a default drop policy, then allow only what you need. Default-deny is the secure baseline.
sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }Allowing SSH
Add a rule to accept incoming TCP on port 22 so you do not lock yourself out before allowing anything else.
sudo nft add rule inet filter input tcp dport 22 acceptAllowing Established Traffic
Permit replies to connections you initiated by accepting established and related traffic. Without this, outbound requests get no responses.
sudo nft add rule inet filter input ct state established,related acceptThe Easier Way: ufw
For everyday use, ufw (Uncomplicated Firewall) is a friendly front-end. It manages the underlying rules with simple commands.
sudo ufw allow 22/tcp
sudo ufw enableChecking ufw Status
Verify which rules ufw has applied and whether it is active.
sudo ufw status verbosePersisting Rules
nftables rules added at the command line vanish on reboot. Save them to /etc/nftables.conf and enable the service so they reload automatically.
sudo nft list ruleset | sudo tee /etc/nftables.conf
sudo systemctl enable nftablesLogging Dropped Packets
Add a logging rule before the final drop so you can see what is being blocked. This is invaluable when a service mysteriously cannot be reached.
sudo nft add rule inet filter input log prefix "dropped: "Quick Check
Test your firewall knowledge.
Recap
You learned to configure the Linux firewall.
- nftables uses tables, chains, and rules with a default-deny baseline.
- Always allow SSH and established traffic before locking down.
- ufw simplifies common rules; persist nftables to survive reboots.
تعلم Linux Networking & TCP/IP for Developers مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 12
- الدروس
- 48
الأسئلة الشائعة
هل درس «تهيئة جدار حماية Linux باستخدام nftables» مجاني؟
نعم — نص درس «تهيئة جدار حماية Linux باستخدام nftables» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Linux Networking & TCP/IP for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Linux Networking & TCP/IP for Developers 4 دروس في المجموع.
ماذا ستتعلم في «تهيئة جدار حماية Linux باستخدام nftables»؟
تحكّم في حركة المرور الواردة والصادرة على مضيف Linux باستخدام nftables وواجهة ufw السهلة لتأمين خدمات الشبكة. تتمرن على Linux Networking & TCP/IP for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Linux Networking & TCP/IP for Developers؟
لا تُشترط خبرة سابقة. Linux Networking & TCP/IP for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «تهيئة جدار حماية Linux باستخدام nftables»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Linux Networking & TCP/IP for Developers هذا؟
نعم. كل درس في Linux Networking & TCP/IP for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إدارة واجهات الشبكة
- جداول التوجيه والبوابات
- ضبط DNS وحلّ الأسماء
- تهيئة جدار حماية Linux باستخدام nftables