دیوارهای آتش

Revision as of 12:25, 15 April 2022 by Argon (talk | contribs) (Created page with "==UFW و برنامه‌های کاربردی==")
Other languages:
English • ‎Türkçe • ‎русский • ‎فارسی • ‎中文(中国大陆)‎

نمای کلّی

اجرای یک دیوارآتش محلی تقریباً همیشه یک تمرین خوب است. حتی زمانی که پشت دیوارآتش شبکه قرار دارید، یک دیوارآتش محلی از شما در برابر تهدیدات داخل شبکه محافظت می کند.

UFW

UFW مخفف Uncomplicated FireWall است و برنامه ای برای مدیریت دیوار‌آتش و فیلتر شبکه است. این یک رابط خط‌فرمان فراهم می کند و هدف آن این است که بدون پیچیدگی و آسان برای استفاده باشد. UFW بسیار ساده‌تر از iptables است و مکان خوبی برای شروع است مگر اینکه نیازهای بسیار تخصصی داشته باشید.

=نصب UFW

می توانید بسته ufw را با استفاده از مدیر بسته مورد علاقه خود یا با دستور زیر نصب کنید:

user $ pamac install ufw COPY TO CLIPBOARD


پس از نصب UFW، باید آن را با استفاده از دستورات زیر شروع کرده و فعال کنید:

user $ sudo systemctl enable ufw.service COPY TO CLIPBOARD


user $ sudo ufw enable COPY TO CLIPBOARD



Warning
هم iptables.service و هم ufw.service را با هم فعال نکنید. ابتدا iptables.service غیرفعال و سپس ufw.service را فعال کنید.

اضافه کردن قوانین

اضافه کردن قوانین

برای مشاهده پیکربندی فعلی می‌توانید از دستور ufw status استفاده کنید. در اینجا در نصب جدید این‌گونه به نظر می‌رسد:


$ sudo ufw status verbose

Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip


این نشان می دهد که تمام ترافیک ورودی را مسدود می کند و به همه ترافیک‌های خروجی اجازه می‌دهد. این نقطه شروع خوبی برای اکثر سامانه های میزکار است. با این حال، اغلب ما می خواهیم به برخی از ترافیک های ورودی اجازه دهیم. این را می توان با دستور ufw allow انجام داد. به عنوان مثال، اگر بخواهیم به ترافیک ssh ورودی اجازه دهیم تا بتوانیم از سایر دستگاه های موجود در شبکه به دستگاه متصل شویم، می توانیم از دستور زیر استفاده کنیم:

user $ sudo ufw allow ssh COPY TO CLIPBOARD


If we wanted to also tcp connections to a local webserver on a non-standard https port, 8443. We could use the command:

user $ sudo ufw allow in 8443/tcp COPY TO CLIPBOARD




Tip
وقتی in یا out را مشخص نمی کنید، in در نظر گرفته می شود

UFW و برنامه‌های کاربردی

You may notice a difference in the above two commands. When we built the rules for ssh we used the name and for https we used the port number, 8443. This is because UFW has a small database of applications it knows the ports for. You can see the list with the command:

user $ sudo ufw app list COPY TO CLIPBOARD


For applications on the list you can add them by name. If you want to review the configuration for one of the applications, you can use the command ufw app info. For example, to the configuration for ssh:


$ sudo ufw app info SSH

Profile: SSH
Title: SSH server
Description: SSH server
 
 
Port:
  22/tcp



Tip
When using ufw app the commands are case sensitive but when adding rules they are not

Some additional preconfigured applications can be added by installing the package ufw-extras with your favorite package manager or the command:

user $ pamac install ufw-extras COPY TO CLIPBOARD


Removing Rules

Rules can be removed with the ufw delete command. For example, to delete our 8443 rules we could use the command:

user $ sudo ufw delete allow 8443/tcp COPY TO CLIPBOARD


You can also delete them by number. This is easier if you have a numbered list which you can see with the command:


$ sudo ufw status numbered

Status: active
To                         Action      From
     --                         ------      ----
[ 1] 22                         ALLOW IN    Anywhere
[ 2] 22 (v6)                    ALLOW IN    Anywhere (v6)


Now if we wanted to stop allowing ssh on ipv6 we could use the command:

user $ sudo ufw delete 2 COPY TO CLIPBOARD


GUFW

Prefer to use GUI applications and still want to manage your firewall? No problem. GUFW is a GTK front-end for UFW that aims to make managing a Linux firewall as accessible and easy as possible. It features pre-sets for common ports and p2p applications.

If it is not installed already gufw can be installed from the repos:

user $ pamac install gufw COPY TO CLIPBOARD


It will now be available in the menu as Firewall Configuration or by running gufw directly.

iptables

iptables is included as part of the Linux kernel. iptables is significantly more complicated than using a tool like UFW. As a result, a full tutorial on iptables is beyond the scope of this wiki. Using iptables on Manjaro should be the same for every distribution of Linux so there is plenty of available documentation. Some of this is linked below. Here are some basics to get you started.

To enable loading rules on startup you can use the command:

user $ sudo systemctl enable iptables.service COPY TO CLIPBOARD


This will load the rules from the file /etc/iptables/iptables.rules.

To display the currently loaded rules:

user $ sudo iptables -L COPY TO CLIPBOARD


To save the current rules to a file

user $ sudo sh -c "iptables-save > /etc/iptables/iptables.rules" /etc/iptables/iptables.rules" " aria-disabled="false">COPY TO CLIPBOARD


To load the rules from a file

user $ sudo sh -c "iptables-restore > /etc/iptables/iptables.rules" /etc/iptables/iptables.rules" " aria-disabled="false">COPY TO CLIPBOARD


To allow ssh connections

user $ sudo iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT COPY TO CLIPBOARD


user $ sudo iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT COPY TO CLIPBOARD


See Also