Linux Networking & TCP/IP for Developers · Урок

Брандмауэр Linux (Netfilter/iptables)

Изучите основы брандмауэров Linux и используйте `iptables` для фильтрации трафика и защиты систем

Урок 3 из 411 шагов

«Брандмауэр Linux (Netfilter/iptables)» — бесплатный урок Linux Networking & TCP/IP for Developers на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 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 -v

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

Blocking 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 DROP

Making 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 Networking & TCP/IP for Developers с ИИ-репетитором — бесплатно

Пиши и запускай код прямо в браузере, получай мгновенную помощь от ИИ-репетитора 24/7 и продолжи учиться на сайте или в приложении.

Курсы
12
Уроки
48

Часто задаваемые вопросы

Урок «Брандмауэр Linux (Netfilter/iptables)» бесплатный?

Да — полный текст урока «Брандмауэр Linux (Netfilter/iptables)» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 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 с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 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 — локальная установка не требуется.

Все уроки этого курса

  1. Перехват пакетов с Wireshark и tcpdump
  2. Инструменты анализа производительности сети
  3. Брандмауэр Linux (Netfilter/iptables)
  4. Диагностика DNS с помощью dig и nslookup
← Назад к Linux Networking & TCP/IP for Developers