مقدمه
در دنیای امروز، امنیت سرور نقش حیاتی در جلوگیری از نفوذ هکرها و حفاظت از دادههای حساس دارد. یکی از ابزارهای قدرتمند و متنباز برای مقابله با حملات Brute-force و دسترسیهای غیرمجاز، Fail2Ban است. این ابزار با تحلیل لاگها و شناسایی IPهای مشکوک، بهطور خودکار آنها را مسدود میکند. در این مقاله بهصورت گامبهگام، نصب و پیکربندی Fail2Ban را آموزش میدهیم تا امنیت سرورتان را به شکل قابلتوجهی ارتقا دهید.
پیشنیازها و آمادهسازی برای نصب Fail2Ban
قبل از شروع، اطمینان حاصل کنید که:
- دسترسی sudo به سرور دارید.
- سیستم عامل شما یکی از توزیعهای لینوکسی رایج مانند Debian/Ubuntu یا CentOS/RHEL باشد.
- پورتهای لازم برای سرویس SSH یا سرویسهای دیگر باز باشند.
نکته امنیتی: بهتر است قبل از تغییر تنظیمات، یک بکاپ کامل از پیکربندی سرور تهیه کنید.
مراحل نصب Fail2Ban بر روی لینوکس
نصب در Debian/Ubuntu
sudo apt update sudo apt install fail2ban -y
نصب در CentOS/RHEL
sudo yum install epel-release -y sudo yum install fail2ban -y
پس از نصب، سرویس Fail2Ban را فعال و اجرا کنید:
sudo systemctl enable fail2ban sudo systemctl start fail2ban
کانفیگ پیشرفته Fail2Ban برای حفاظت حداکثری
ایجاد فایل local برای جلوگیری از تغییرات در فایلهای اصلی
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
تنظیمات اولیه در jail.local
- ignoreip: آیپیهایی که هرگز بلاک نمیشوند.
- bantime: مدت زمان مسدودی آیپی (مثلاً 600 ثانیه).
- findtime: بازه زمانی بررسی برای لاگینهای ناموفق.
- maxretry: تعداد دفعات مجاز تلاش ناموفق.
نمونه تنظیم:
[DEFAULT] ignoreip = 127.0.0.1/8 192.168.1.100 bantime = 3600 findtime = 600 maxretry = 3
فعالسازی محافظت از SSH
[sshd] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3
برای CentOS مسیر لاگ متفاوت است:
logpath = /var/log/secure
بررسی سرویسهای فعال در Fail2Ban
sudo fail2ban-client status sudo fail2ban-client status sshd

تنظیم ارسال ایمیل هشدار
با افزودن بخش زیر میتوانید هنگام بلاک شدن IP هشدار دریافت کنید:
destemail = admin@example.com sender = fail2ban@example.com mta = sendmail action = %(action_mwl)s
نکات امنیتی و بهینهسازی
- از بازههای زمانی و مدت مسدودسازی بلندتر برای سرورهای حساس استفاده کنید.
- Fail2Ban را بهروز نگه دارید تا از آخرین بهبودهای امنیتی بهرهمند شوید.
- در صورت استفاده از چند سرویس (مانند FTP، Mail و Apache) برای هر سرویس Jail مستقل تعریف کنید.
نتیجهگیری
Fail2Ban ابزاری قدرتمند برای مقابله با حملات Brute-force و مسدودسازی خودکار IPهای مخرب است. با نصب و کانفیگ صحیح این نرمافزار، میتوانید امنیت سرور خود را به شکل قابلتوجهی افزایش دهید و از بروز بسیاری از تهدیدهای امنیتی جلوگیری کنید. همین حالا با اجرای مراحل بالا سرور خود را ایمنتر کنید و خطر هک را کاهش دهید.




jdbkknet has completely changed how I enjoy online gaming. The mobile app works perfectly even on older devices and the support team answers in no time. I appreciate how transparent they are with their terms and I keep coming back for the daily rewards. jdbkknet
Sports trading can be a tricky game, but this platform makes it feel like a friendly chat with a seasoned pro. I appreciate how transparent the market tools are and how responsive the support team is during big match days. It really helps me stay ahead of the curve without overcomplicating things. A solid pick for anyone who enjoys strategic play and wants clear analytics. Check it out and let me know what you think! ecsportytrader
The VIP program actually rewards loyalty in meaningful ways and I love the weekly tournaments. Everything runs smoothly and the support chat is always friendly when I need a quick answer. Highly recommend it. topwincasino
Such a friendly community and the support team is actually helpful. It feels more personal than other sites. Glad I found phjdlove.
The data and insights here are incredibly helpful for my strategy. It is a must visit for anyone serious about their game. Check idpaitoangka
I appreciate how transparent this site is with its terms. It makes me feel safe and confident while playing. sersanbetslot is a winner in my book.
Playing slots on this platform has been such a smooth experience for me and my friends. The bonuses roll in regularly and customer support actually picks up fast. I highly recommend you check out bdtkabet if you want a reliable spot to unwind after a long day. bdtkabet
Curious about the mechanics? The product info is helpful, but remember to check out nino mulach slot for a broader view. It’s smart to understand the features before diving in; casual play requires careful reading!