انتقل إلى المحتوى

الدروس الخوادم متوسط1 دقائق قراءة

How to Set Up a Firewall with UFW on Ubuntu

Use UFW to allow only the traffic your server needs: SSH, web and mail, plus rate limiting, rule management and avoiding lockouts.

بواسطة فريق تحرير ZSOLNET آخر تحديث

هذه الصفحة غير متاحة بالعربية بعد، لذا تُعرض بالإنجليزية.

أهم النقاط

  • Deny incoming by default and allow only required ports.
  • Allow SSH before enabling UFW to avoid lockout.
  • Provider firewalls and UFW must both allow a port.

UFW (Uncomplicated Firewall) is the simplest way to manage firewall rules on Ubuntu.

Default policy

Deny incoming connections and allow outgoing ones:

sudo ufw default deny incoming
sudo ufw default allow outgoing

Allow what you need

Always allow SSH before enabling the firewall:

sudo ufw allow OpenSSH

Then the services you run:

sudo ufw allow 'Nginx Full'     # ports 80 and 443
sudo ufw allow 25,465,587/tcp   # only if you run a mail server

Restrict a service to one IP address — for example a database accessed only by your app server:

sudo ufw allow from 198.51.100.7 to any port 3306 proto tcp

Enable and check

sudo ufw enable
sudo ufw status verbose

Rate-limit SSH

Slow down password-guessing by limiting repeated connections:

sudo ufw limit OpenSSH

Remove a rule

sudo ufw status numbered
sudo ufw delete 3
شارك X LinkedIn Facebook

الدخول إلى حسابك

أدِر نطاقاتك واستضافتك وفواتيرك من مكان واحد.

اتصال آمن مباشرة مع منطقة العملاء في ZSOLNET.

ليس لديك حساب؟