fail2ban 使用

1.安装简单,

yum install fail2ban

修改一个参数

31 # Values: [ STDOUT | STDERR | SYSLOG | FILE ]  Default: STDERR
 32 #
 33 logtarget = /var/log/fail2ban.log
 34 
 35 # Option: socket
把日志输出到文件,这样就可以清晰的看到一些执行输出了

2.启动

/etc/init.d/fail2ban start

3.测试 ssh

[root@test ~]# ssh root@10.210.71.145
root@10.210.71.145's password: 
Permission denied, please try again.
root@10.210.71.145's password: 
Permission denied, please try again.
root@10.210.71.145's password: 
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[root@test ~]# ssh root@10.210.71.145
root@10.210.71.145's password: 
Permission denied, please try again.
root@10.210.71.145's password: 
Permission denied, please try again.
root@10.210.71.145's password: 
qwqwqw
wqwqwqwqw
qwqwqwqw

iptables

[root@test ~]# cat /etc/hosts|grep 'test.143'
10.210.71.143   test.143
[root@test ~]#  iptables -L 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
fail2ban-SSH  tcp  --  anywhere             anywhere            tcp dpt:ssh 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain fail2ban-SSH (1 references)
target     prot opt source               destination         
REJECT     all  --  test.143             anywhere            reject-with icmp-port-unreachable 
RETURN     all  --  anywhere             anywhere 

日志输出

[root@test log]# tail -f fail2ban.log 
From: Fail2Ban <fail2ban@example.com>
To: you@example.com\n
Hi,\n
The IP 10.210.71.143 has just been banned by Fail2Ban after
6 attempts against SSH.\n\n
Here is more information about 10.210.71.143:\n
`/usr/bin/whois 10.210.71.143 || echo missing whois program`\n
Regards,\n
Fail2Ban" | /usr/sbin/sendmail -f fail2ban@example.com you@example.com returned 4b00
2014-09-16 10:16:51,246 fail2ban.actions[28550]: WARNING [ssh-iptables] Unban 10.210.71.143
2014-09-16 10:19:50,545 fail2ban.actions[28550]: WARNING [ssh-iptables] Ban 10.210.71.143
2014-09-16 10:19:50,767 fail2ban.actions.action[28550]: ERROR   printf %b "Subject: [Fail2Ban] SSH: banned 10.210.71.143 from `uname -n`
Date: `LC_TIME=C date -u +"%a, %d %h %Y %T +0000"`
From: Fail2Ban <fail2ban@example.com>
To: you@example.com\n
Hi,\n
The IP 10.210.71.143 has just been banned by Fail2Ban after
5 attempts against SSH.\n\n
Here is more information about 10.210.71.143:\n
`/usr/bin/whois 10.210.71.143 || echo missing whois program`\n
Regards,\n
Fail2Ban" | /usr/sbin/sendmail -f fail2ban@example.com you@example.com returned 4b00

具体细节根据情况配置

比如Apache的accesslog errorlog 什么的。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值