大网数据广告活动
服务器运维问答

Setting Up Fail2Ban

· 52CE 我爱测

I am new to fail2ban. I want to setup Fail2Ban such that it bans an IP for one hour on two failed login attempts. I have the following setup: /etc/fail2ban/jail.local.conf [DEFAULT] bantime = 3600 maxretry = 2 backend = systemd u…

问题原文

原帖链接 · Abrar Hossain · CC BY-SA 4.0

I am new to fail2ban. I want to setup Fail2Ban such that it bans an IP for one hour on two failed login attempts. I have the following setup:

/etc/fail2ban/jail.local.conf

[DEFAULT]
bantime = 3600
maxretry = 2
backend = systemd
usedns = warn
mode = normal
destemail = <MYEMAIL>
sender = <MYSENDER>
protocol = tcp
chain = <known/chain>
port = 0:65535
fail2ban_agent = Fail2Ban/%(fail2ban_version)s
...
# Choose default action.  To change, just override value of 'action' with
# the interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_mw)s

[sshd]

# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
port    = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s


[dropbear]

port     = ssh
logpath  = %(dropbear_log)s
backend  = %(dropbear_backend)s


[selinux-ssh]

port     = ssh
logpath  = %(auditd_log)s

On systemctl status fail2ban.service I see the service is up. My assumption is it is using the jail.local.conf file. There are no errors reported. I don't have iptables installed. Is that necessary? If so, how do I set it up with my existing fail2ban setup?

已采纳解答

原帖链接 · David · CC BY-SA 4.0

I guess better later than never, so I'll post an answer to this, if anyone stumbles upon it like I did.

Do you need iptables?

Basically, Yes, you need iptables. At least for fail2ban to work properly.

Simply use the apt-get install iptables to make that happen.



How to setup your fail2ban jails?

Now to the first question.

Basically to setup your fail2ban to run properly (after installing it properly), you need to make a copy of the file jail.conf and edit that file. Then reload the service to have it run according to your setup.

I'm detailing that below, but first: install fail2ban.


  1. Copy of the jail.conf file:
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

  1. Now that you have the copy, make the edits you want, then save the edits and exit the file.
nano /etc/fail2ban/jail.local

You could add your own IP to prevent locking yourself out for example.
For that, find the [DEFAULT] row, below that, find the row that starts with #ignoreip, uncomment it, and paste your IPs (separated by a space).


  1. You're all set now, you just need to restart fail2ban. For that just use the following command.
service fail2ban restart

You can check the status of your jails with the following command:
fail2ban-client status sshd

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。