Zapora sieciowa Linux (Netfilter/iptables)
Poznaj podstawy zapór sieciowych w systemie Linux z użyciem `iptables` do filtrowania ruchu i zabezpieczania systemów.
Zapora sieciowa Linux (Netfilter/iptables) to bezpłatna lekcja Linux Networking & TCP/IP for Developers na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Linux Networking & TCP/IP for Developers, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Linux Networking & TCP/IP for Developers zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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!
Często zadawane pytania
Czy lekcja „Zapora sieciowa Linux (Netfilter/iptables)” jest bezpłatna?
Tak — pełny tekst „Zapora sieciowa Linux (Netfilter/iptables)” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Linux Networking & TCP/IP for Developers, przejdź na CoddyKit PRO. Kurs Linux Networking & TCP/IP for Developers zawiera 4 lekcji w sumie.
Co nauczysz się w „Zapora sieciowa Linux (Netfilter/iptables)”?
Poznaj podstawy zapór sieciowych w systemie Linux z użyciem `iptables` do filtrowania ruchu i zabezpieczania systemów. Ćwiczysz Linux Networking & TCP/IP for Developers z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Linux Networking & TCP/IP for Developers?
Nie wymagamy żadnego doświadczenia. Linux Networking & TCP/IP for Developers w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „Zapora sieciowa Linux (Netfilter/iptables)”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Linux Networking & TCP/IP for Developers?
Tak. Każda lekcja Linux Networking & TCP/IP for Developers zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Przechwytywanie pakietów za pomocą Wireshark/tcpdump
- Narzędzia do badania wydajności sieci
- Zapora sieciowa Linux (Netfilter/iptables)
- Diagnostyka DNS za pomocą dig i nslookup