当前位置:首页 > 行业动态 > 正文

如何使用Fail2ban工具防止暴力破解尝试

Fail2ban是一个用于防止暴力破解尝试的工具,可以通过配置文件和日志文件来监控和阻止反面IP地址。

Fail2ban是一款用于防止暴力破解尝试的工具,它可以监控日志文件,检测非规登录尝试,并在发现可疑行为时自动封禁IP地址,本文将详细介绍如何使用Fail2ban工具防止暴力破解尝试。

安装Fail2ban

1、在基于Debian的系统(如Ubuntu)上安装Fail2ban:

sudo aptget update
sudo aptget install fail2ban

2、在基于RPM的系统(如CentOS)上安装Fail2ban:

sudo yum install epelrelease
sudo yum install fail2ban

配置Fail2ban

1、创建配置文件目录:

sudo mkdir /etc/fail2ban
sudo chown root:root /etc/fail2ban
sudo chmod 750 /etc/fail2ban

2、创建Fail2ban主配置文件:

sudo nano /etc/fail2ban/fail2ban.conf

3、在主配置文件中,启用所需的守护进程和模块,启用SSH守护进程和iptables模块:

[Definition]
省略其他部分...
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
findtime = 600
bantime = 86400
action_ = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
ignoreip = 127.0.0.1/8
backend = auto
usedns = warn
destemail = root@localhost
sendername = Fail2Ban <root@localhost>
mta = sendmail
protocol = tcp
chain = INPUT
action_mw = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)swhois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mwl = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)swhoislines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
             %(mta)swhois[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
action_mwl_lines = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)swhoislines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
             %(mta)swhois[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
action_mwh = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)swhois[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
action_naze = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]sendmailwhois[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"] action_mwl = %(banaction)
0

随机文章