Linuxファイアウォール(Netfilter/iptables)
`iptables`を使ってトラフィックをフィルタリングし、システムを保護するLinuxファイアウォールの基礎を理解します。
「Linuxファイアウォール(Netfilter/iptables)」はCoddyKit上の無料Linux Networking & TCP/IP for Developersレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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)」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Networking & TCP/IP for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。
「Linuxファイアウォール(Netfilter/iptables)」で何を学びますか?
`iptables`を使ってトラフィックをフィルタリングし、システムを保護するLinuxファイアウォールの基礎を理解します。 ブラウザで直接実行するハンズオンコードでLinux Networking & TCP/IP for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Networking & TCP/IP for Developersを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Networking & TCP/IP for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン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)
- digとnslookupによるDNS診断