Управление брандмауэром: `ufw`, `firewalld`, `iptables`
Научитесь настраивать брандмауэры и управлять ими, чтобы защищать систему Linux от несанкционированного доступа.
«Управление брандмауэром: `ufw`, `firewalld`, `iptables`» — бесплатный урок Linux Command Line Mastery на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Linux Command Line Mastery, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Linux Command Line Mastery содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
What's a Firewall?
A firewall acts as a security guard for your computer or network. It controls incoming and outgoing network traffic by analyzing data packets and deciding whether to allow or block them based on a set of predefined rules.
Think of it as a filter that protects your system from unauthorized access and malicious threats.
Introducing UFW
UFW, which stands for "Uncomplicated Firewall," is a user-friendly front-end for iptables, the complex default firewall utility in Linux. It's designed to make firewall management much simpler, especially for users on Debian-based systems like Ubuntu.
UFW simplifies common tasks like opening or closing ports.
UFW Status & Control
Before making changes, it's good practice to check UFW's current status. You can also easily enable or disable it.
Try running these commands:
sudo ufw status
sudo ufw enable
sudo ufw disableUFW: Allow Services
UFW allows you to open ports for common services by their name, which is very convenient. For example, to allow SSH or HTTP traffic, you just use the service name.
Let's try allowing SSH and HTTP:
sudo ufw allow ssh
sudo ufw allow http
sudo ufw status verboseUFW: Allow Custom Ports
Sometimes you need to open a specific port that isn't a named service. You can do this by specifying the port number and the protocol (TCP or UDP).
Here's how to allow port 8080 for TCP and 53 for UDP:
sudo ufw allow 8080/tcp
sudo ufw allow 53/udp
sudo ufw status verboseIntroducing Firewalld
Firewalld is another popular firewall management tool, often found on Red Hat-based systems like CentOS and Fedora. Unlike UFW, Firewalld is a dynamic firewall manager.
It uses zones to define different trust levels for network connections, allowing you to apply rules based on where the connection originates.
Firewalld Status & Zones
With Firewalld, you can check its status and explore the various zones it uses. Zones like public, home, or internal have different default rules.
Check the status and active zones:
sudo systemctl status firewalld
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-zonesFirewalld: Manage Services
To manage services with Firewalld, you specify the zone and the service name. Changes are temporary by default; use --permanent to make them stick after a reboot, then --reload to apply.
Let's add HTTP service to the public zone permanently:
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-services --zone=publicFirewalld: Manage Ports
Similar to services, you can open or close specific port numbers in a Firewalld zone. Remember to specify the protocol (TCP or UDP) and use --permanent for lasting changes.
Here's how to open port 8080 for TCP permanently:
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports --zone=publicFirewall Commands Check
Time for a quick check! Which of the following statements about firewall management in Linux are true?
Recap: Firewall Essentials
In this lesson, we explored how to manage firewalls on Linux systems to enhance security. We covered two main tools:
- UFW (Uncomplicated Firewall): A simple interface for
iptables, popular on Debian/Ubuntu, allowing easy control over services and ports. - Firewalld: A dynamic firewall manager used on RHEL/CentOS systems, which organizes rules into zones for flexible security policies.
Understanding these tools is crucial for securing your Linux server or workstation.
Часто задаваемые вопросы
Урок «Управление брандмауэром: `ufw`, `firewalld`, `iptables`» бесплатный?
Да — полный текст урока «Управление брандмауэром: `ufw`, `firewalld`, `iptables`» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Linux Command Line Mastery, подпишись на CoddyKit PRO. Курс Linux Command Line Mastery содержит 4 уроков всего.
Чему я научусь в уроке «Управление брандмауэром: `ufw`, `firewalld`, `iptables`»?
Научитесь настраивать брандмауэры и управлять ими, чтобы защищать систему Linux от несанкционированного доступа. Ты практикуешь Linux Command Line Mastery с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Linux Command Line Mastery?
Предыдущий опыт не требуется. Linux Command Line Mastery на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.
Сколько времени занимает урок «Управление брандмауэром: `ufw`, `firewalld`, `iptables`»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Linux Command Line Mastery?
Да. Каждый урок Linux Command Line Mastery включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Диагностика сети: `traceroute`, `nslookup`, `dig`
- Управление брандмауэром: `ufw`, `firewalld`, `iptables`
- Управление ключами безопасной оболочки
- Захват и анализ трафика с tcpdump