---
title: "fail2ban 安装指南"
author: "IEQQ"
date: "2015-04-02T10:12:22Z"
tags: ["Linux", "SSH", "Security"]
categories: ["操作系统"]
slug: "fail2ban"
draft: false
lastmod: "2016-08-12T17:50:33Z"
id: 2198044
url: "https://ieqq.iteye.com/blog/2198044"
---

官网 <http://www.fail2ban.org/wiki/index.php/Downloads>
 找到适合自己操作系统的版本。
Red Hat/CentOS 	RPMs are available through EPEL. 
 跳转到EPEL网站 <http://fedoraproject.org/wiki/EPEL>
 切换到中文版 <https://fedoraproject.org/wiki/EPEL/zh-cn>
 找到符合自己的操作系统版本 
 如果您使用第6代企业版 Linux，请通过这个链接安装 epel-release 包的最新版本: 
 进入EPEL安装包下载点： <http://ftp.nluug.nl/pub/os/Linux/distr/fedora-epel/6/i386/repoview/epel-release.html>
 下载并安装EPEL 
epel-release-6-8.noarch  	Changelog by (2012-11-04): 
直接用浏览器下载，或者用下面的命令：

```shell
wget http://ftp.nluug.nl/pub/os/Linux/distr/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
 
rpm -ivh release-6-8.noarch.rpm 
```

 终于到了正题， 安装fail2ban

```shell
 yum install fail2ban -y 
```

 配置fail2ban

```shell
vim /etc/fail2ban/jail.conf
```

找到sshd-ddos的小节： 把enable 改成 true 来让该过滤项生效。
maxretry 最大重试的次数可以改成3


```properties

enabled  = true
filter   = sshd-ddos
action   = iptables[name=SSHDDOS, port=ssh, protocol=tcp]
logpath  = /var/log/sshd.log
maxretry = 3

```

 生成一个log文件先，某些版本不会自动生成log文件，需要你帮它创建好一个先。

```shell
echo "" > /var/log/sshd.log
```

 加入开机启动项 

```shell
chkconfig fail2ban on
```

 启动服务

```shell
service fail2ban start
```