首页 > 系统相关 >Centos中Fail2ban配置

Centos中Fail2ban配置

时间:2023-12-16 12:07:39浏览次数:29  
标签:iptables Centos 0.0 配置 192.168 Fail2ban root ssh fail2ban

安装可以使用源码编译 官网 或者yum安装

安装

(base) [root@www fail2ban]# yum -y install fail2ban

配置

#配置
(base) [root@www fail2ban]# vim jail.conf 
 加入以下内容
 42 [ssh-iptables]
 43 enabled = true
 44 filter = sshd
 45 action = iptables[name=SSH, port=ssh, protocol=tcp]
 46 sendmail-whois[name=SSH, [email protected], [email protected]]
 47 logpath = /var/log/secure
 48 maxretry = 3
 49 bantime = 3600
 50 findtime = 300

重启fail2ban

(base) [root@www fail2ban]# systemctl restart fail2ban

测试效果

[root@NFS ~]# ssh 192.168.100.119
[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[root@NFS ~]# ssh 192.168.100.119
ssh: connect to host 192.168.100.119 port 22: Connection refused
可以在/var/log/secure 查看日志信息

查看iptables规则

(base) [root@www fail2ban]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
f2b-SSH    tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:22

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain f2b-SSH (1 references)
target     prot opt source               destination         
REJECT     all  --  192.168.100.155      0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  192.168.100.157      0.0.0.0/0            reject-with icmp-port-unreachable
RETURN     all  --  0.0.0.0/0            0.0.0.0/0           
(base) [root@www fail2ban]#
使用fail2ban-client 查看状态
(base) [root@www fail2ban]# fail2ban-client status ssh-iptables 
Status for the jail: ssh-iptables
|- Filter
|  |- Currently failed:	0
|  |- Total failed:	6
|  `- File list:	/var/log/secure
`- Actions
   |- Currently banned:	2
   |- Total banned:	2
   `- Banned IP list:	192.168.100.155 192.168.100.157

解锁特定的ip

(base) [root@www fail2ban]# fail2ban-client set ssh-iptables unbanip 192.168.100.155
1
(base) [root@www fail2ban]# fail2ban-client status ssh-iptables 
Status for the jail: ssh-iptables
|- Filter
|  |- Currently failed:	0
|  |- Total failed:	6
|  `- File list:	/var/log/secure
`- Actions
   |- Currently banned:	1
   |- Total banned:	2
   `- Banned IP list:	192.168.100.157
注意,如果你停止了Fail2ban 服务,那么所有的IP地址都会被解锁。当你重启 Fail2ban,它会从/etc/log/secure(或 /var/log/auth.log)中找到异常的IP地址列表,如果这些异常地址的发生时间仍然在禁止时间内,那么Fail2ban会重新将这些IP地址禁止。

标签:iptables,Centos,0.0,配置,192.168,Fail2ban,root,ssh,fail2ban
From: https://blog.51cto.com/u_16445335/8850895

相关文章

  • 线程组内几个配置原件的说明
    一、http信息头管理器1、设置请求接口提交参数的格式,一般接口的开发文档文档会有相应的说明,类型会有application,x-www-form-urlencoded等,application是提交的参数以json的格式发送,x-www-form-urlencoded是以浏览器默认表达的方式提交,根据接口说明文档设置即可二、http请求默认......
  • logging 配置说明
    Java项目中经常会用到 logging包来记录日志,下面记录常见的配置说明。配置通常放在boostrap.yml或application.yml这些配置文件中。1#日志配置2logging:3pattern:4#console:"%msg%n"5#console:"%d{yyyy-MM-ddHH:mm:ss}-%msg%n"6#console:......
  • PowerShell配置文件只Profile.ps1
    PowerShell执行的时候,首先会执行Profile.ps1的内容,如果我们想要执行PowerShell的时候,会获得某些功能,可以将想要的内容放到Profile.ps1中。这个文件默认存放在C:\Windows\system32\WindowsPowerShell\v1.0\Examples\下。该文件默认添加所有的别名,还有部分Function。内容如下:#Copyr......
  • HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容。没有为请求的
    HTTP错误403.14-ForbiddenWeb服务器被配置为不列出此目录的内容。出现以上这个错误可能有如下解决方法:1.将应用程序池设置成V4.02.在配置文件中加上以下几句代码:<system.webServer><modulesrunAllManagedModulesForAllRequests=“true”/><directoryBrowseenabled=“......
  • 【Power Shell】启动时自动配置http代理
    背景有时候我们经常需要在WindowsTerminal,powershell内使用http代理来拉去GitHub代码、软件包等等,每次都需要手动配置很麻烦。其实我们可以使用.ps1脚本来启动。https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_scripts?view=pow......
  • EFCore 实体的配置FluentAPI(3)
    上一篇文章简述了如何使用EFCore的CodeFirst进行数据库创建并实现简单的增删改查,这章我们讨论一些复杂的配置:实体配置实体配置目的:生成想要的表格类型,如表名,表的列名,表字段类型,长度等,下图是上一章EFCore生成的表 实体配置遵循约定大于配置的原则:就是说EFCore这个ORM框架已经......
  • 常用docker 配置2023
    https://docs.docker.com/engine/install/ubuntu/安装Docker引擎编辑配置文件/mysql/conf/my.cnf[mysql]#设置mysql客户端默认字符集default-character-set=UTF8MB4[mysqld]#设置3306端口port=3306#允许最大连接数max_connections=200#允许连接失败的次数max_connect_errors=10#......
  • gitlabrunner之executor配置拉取镜像的账户密码
    dockerexecutor$catconfig.toml......[[runners]]environment=["DOCKER_AUTH_CONFIG={\"auths\":{\"registry.xxx.com\":{\"auth\":\"dmlwZXIucm9ib3QuZG9ja2VyOlNUYWkyMDIzLm\"}}}"]......k8sexec......
  • sqlmap的配置及基本用法
    SQLMap是一款非常强大的开源SQL注入测试工具,它能够帮助我们发现并利用潜在的SQL注入漏洞。SQLMap是基于Python开发的自动化SQL注入工具,其原理是通过构造恶意SQL查询语句,探测和利用目标网站的SQL注入漏洞。SQLMap通过发送不同类型的SQL查询请求,从而判断目标网站是否存在SQL注入漏洞,......
  • centos系统YUM慢怎么办?
    一、用Centos镜像搭建本地Yum源  由于安装centos后的默认Yum源为centos的官方地址,所以在国内使用很慢甚至无法访问,所以一般的做法都是把默认的Yum源替换成aliyun的Yum源或者163等国内的Yum源(下文介绍如何配置)。 但是以上的方法都是需要网络的,当没有网络的时候就无法使用了,......