ไฟร์วอลล์ Linux (Netfilter/iptables)
ทำความเข้าใจพื้นฐานไฟร์วอลล์ Linux โดยใช้ `iptables` เพื่อกรองทราฟฟิกและรักษาความปลอดภัยให้ระบบ
ไฟร์วอลล์ Linux (Netfilter/iptables) เป็นบทเรียน Linux Networking & TCP/IP for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Linux Networking & TCP/IP for Developers และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Linux Networking & TCP/IP for Developers มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Firewalls: Your Network Guardian
What is a firewall? It's like a security guard for your network, controlling what traffic goes in and out. In Linux, the core firewall framework is called Netfilter. We use a command-line tool called iptables to manage its rules.
Netfilter: The Kernel's Core
Netfilter is a powerful framework built right into the Linux kernel. It allows different kernel modules to inspect, modify, and drop network packets.
Think of it as the engine behind the firewall. It provides "hooks" where packet processing can be intercepted.
`iptables`: Managing Firewall Rules
While Netfilter is in the kernel, iptables is the command-line utility you use to interact with it. It lets you define rules that tell Netfilter what to do with specific packets.
These rules are organized into tables and chains, which we'll explore next.
`iptables` Chains: Traffic Paths
iptables organizes rules into chains. These are ordered lists of rules that packets are checked against. The three most common built-in chains are:
- INPUT: For packets destined for the local system.
- OUTPUT: For packets originating from the local system.
- FORWARD: For packets passing through the system (e.g., a router).
Default Actions: Chain Policies
Each chain has a default policy, which is the action taken if no rule in the chain matches a packet. Common policies are:
- ACCEPT: Let the packet through.
- DROP: Silently discard the packet (sender gets no response).
- REJECT: Discard the packet and send an error message back to the sender.
It's common to set default policies to DROP for security.
Viewing Current `iptables` Rules
Before adding rules, it's good to see what's already there. You can list all current iptables rules with the -L option. Adding -n shows IP addresses numerically, and -v adds verbosity.
sudo iptables -L -n -vAllowing Inbound SSH Traffic
Let's add a rule to allow incoming SSH connections (port 22). We'll append (-A) this rule to the INPUT chain, specifying TCP protocol (-p tcp) and destination port (--dport 22). The action (-j) will be ACCEPT.
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTBlocking Outbound Ping Requests
Now, let's block all outbound ping requests (ICMP protocol). We'll append this rule to the OUTPUT chain, specifying the ICMP protocol. The action will be DROP.
This means your system won't send ping requests, but might still receive them if not blocked on INPUT.
sudo iptables -A OUTPUT -p icmp -j DROPMaking Rules Permanent
iptables rules are volatile; they disappear on reboot! To make them permanent, you need to save them. On many systems, you'd use iptables-save to export rules and iptables-restore to load them.
Some Linux distributions use specific services (like netfilter-persistent) or files (e.g., /etc/sysconfig/iptables) to manage persistence.
Firewall Chains Check
Based on what you've learned, which iptables chain would typically handle network packets that are trying to reach a service running on your local machine?
Recap: `iptables` Firewall Basics
You've learned about Netfilter, the kernel's firewall framework, and iptables, the user-space tool to manage its rules. We covered the main chains (INPUT, OUTPUT, FORWARD) and policies (ACCEPT, DROP, REJECT).
You also saw how to list, add basic rules, and the importance of saving them for persistence. This is a crucial step in securing any Linux system!
คำถามที่พบบ่อย
บทเรียน “ไฟร์วอลล์ Linux (Netfilter/iptables)” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ไฟร์วอลล์ Linux (Netfilter/iptables)” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Networking & TCP/IP for Developers ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Networking & TCP/IP for Developers มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ไฟร์วอลล์ Linux (Netfilter/iptables)”
ทำความเข้าใจพื้นฐานไฟร์วอลล์ Linux โดยใช้ `iptables` เพื่อกรองทราฟฟิกและรักษาความปลอดภัยให้ระบบ คุณปฏิบัติ Linux Networking & TCP/IP for Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Networking & TCP/IP for Developers หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Networking & TCP/IP for Developers บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “ไฟร์วอลล์ Linux (Netfilter/iptables)” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Linux Networking & TCP/IP for Developers นี้ได้ไหม
ได้ บทเรียน Linux Networking & TCP/IP for Developers ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การจับแพ็กเก็ตด้วย Wireshark/tcpdump
- เครื่องมือวัดประสิทธิภาพเครือข่าย
- ไฟร์วอลล์ Linux (Netfilter/iptables)
- การวินิจฉัย DNS ด้วย dig และ nslookup