Linux Networking & TCP/IP for Developers · บทเรียน

การกำหนดค่าไฟร์วอลล์ Linux ด้วย nftables

ควบคุมทราฟฟิกขาเข้าและขาออกบนโฮสต์ Linux ด้วย nftables และส่วนหน้า ufw ที่ใช้งานง่าย เพื่อรักษาความปลอดภัยให้บริการเครือข่าย

บทเรียน 4 จาก 413 ขั้นตอน

การกำหนดค่าไฟร์วอลล์ Linux ด้วย nftables เป็นบทเรียน Linux Networking & TCP/IP for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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 ruleset

A 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 accept

Allowing 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 accept

The 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 enable

Checking ufw Status

Verify which rules ufw has applied and whether it is active.

sudo ufw status verbose

Persisting 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 nftables

Logging 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 ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การกำหนดค่าไฟร์วอลล์ Linux ด้วย nftables” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การกำหนดค่าไฟร์วอลล์ Linux ด้วย nftables” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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 ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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 ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การจัดการส่วนติดต่อเครือข่าย
  2. ตารางเส้นทางและเกตเวย์
  3. การกำหนดค่าและการแปลงชื่อ DNS
  4. การกำหนดค่าไฟร์วอลล์ Linux ด้วย nftables
← กลับไปที่ Linux Networking & TCP/IP for Developers