CentOS 6和7版本环境安装Fail2ban服务来防止暴力破解FTP/SSH
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

如果出于各种少折腾的需求,如果能不用VPS尽量我们建站的时候就不要用VPS,因为在很多时候我们会受到来自各种主动与非主动的攻击问题出现。一旦出现问题,我们就需要花费大量的时间和精力去解决这样的问题。刚才在寻找是否有些教程可以写的时候看到这篇关于Fail2ban应用文章,于是也就整理过来分享。
基于CentOS 6或者7版本的系统,我们可以安装Fail2ban工具来阻止一定的暴力破解SSH或者FTP账户问题,也许不能足够的解决问题,但至少可以解决一般的问题。
第一、Fail2ban安装
A – CentOS 6
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install fail2ban
B – CentOS 7
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
yum install fail2ban
选择对应的系统进行脚本一键安装,在安装过程中会出现三次是否需要输入Y的步骤,我们输入y且回车继续到最后。
第二、Fail2ban设置
编辑/etc/fail2ban/jail.conf文件,我们需要设置Fail2ban配置文件。
[DEFAULT]
# \\”ignoreip\\” can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1/8
# External command that will take an tagged arguments to ignore, e.g. ,
# and return true if the IP is to be ignored. False otherwise.
#
# ignorecommand = /path/to/command
ignorecommand =
# \\”bantime\\” is the number of seconds that a host is banned.
bantime = 600
# A host is banned if it has generated \\”maxretry\\” during the last \\”findtime\\”
# seconds.
findtime = 600
# \\”maxretry\\” is the number of failures before a host get banned.
maxretry = 3
# \\”backend\\” specifies the backend used to get files modification.
# Available options are \\”pyinotify\\”, \\”gamin\\”, \\”polling\\” and \\”auto\\”.
# This option can be overridden in each jail as well.
#
# pyinotify: requires pyinotify (a file alteration monitor) to be installed.
# If pyinotify is not installed, Fail2ban will use auto.
# gamin: requires Gamin (a file alteration monitor) to be installed.
# If Gamin is not installed, Fail2ban will use auto.
# polling: uses a polling algorithm which does not require external libraries.
# auto: will try to use the following backends, in order:
# pyinotify, gamin, polling.
backend = auto
# \\”usedns\\” specifies if jails should trust hostnames in logs,
# warn when DNS lookups are performed, or ignore all hostnames in logs
#
# yes: if a hostname is encountered, a DNS lookup will be performed.
# warn: if a hostname is encountered, a DNS lookup will be performed,
# but it will be logged as a warning.
# no: if a hostname is encountered, will not be used for banning,
# but it will be logged as info.
usedns = warn
一般,我们设置这几个就可以,具体的含义如下:
ignoreip = 127.0.0.1 #忽略的IP列表,不受设置限制(白名单)
bantime = 600 #屏蔽时间,单位:秒
findtime = 600 #这个时间段内超过规定次数会被ban掉
maxretry = 3 #最大尝试次数
backend = auto #日志修改检测机制(gamin、polling和auto这三种)
[ssh-iptables] #针对各服务的检查配置,如设置bantime、findtime、maxretry和全局冲突,服务优先级大于全局设置
enabled = true #是否激活此项(true/false)
filter = sshd #过滤规则filter的名字,对应filter.d目录下的sshd.conf
action = iptables[name=SSH, port=ssh, protocol=tcp] #动作的相关参数
sendmail-whois[name=SSH, dest=root, [email protected]] #触发报警的收件人
logpath = /var/log/secure #检测的系统的登陆日志文件
maxretry = 5 #最大尝试次数
第三、启动fail2ban
CentOS 6:
service fail2ban restart
CentOS 7:
systemctl restart fail2ban.service
第四、设置开机启动
CentOS 6:
chkconfig fail2ban on
CentOS 7:
systemctl enable fail2ban
总结,这样我们就在自己的VPS中启动和设置Fail2ban设置,可以稍微的防护短暂的IP重复尝试的访问我们的VPS然后给予限制的手段。当然,一般我们正常的网站,如果不去招惹别人,一般别人也不会太无聊的。
[Fail2ban]历史优惠活动内容
猜你可能想看的VPS
- STSDUST→$25 月 2 核 2GB 内存 20GB 空间 10T虚拟空间(主机)
- 滴滴云 3 月采购季重磅启动 云服务器 1 折起助力中小企业上云 1C2全球[VPS测评]
- 双十一 磐石云→美国高防不限流量云主机低至¥27.5 月 邀请用户可享受美国VPS[主机]
- 性价比过低-NexusBytes→$21 年 384MB 内存 5GB 全球[VPS测评]
- 线路不行-Wired Blade→$5 月 2GB 内存 20GB NV全球[VPS测评]
- 感恩节优惠 iON→美国洛杉矶机房 VPS 年付低至 4 折 2 核 2美国VPS[主机]
- 消息 迪拜主机商 hostsailor 近期会接入 CN2 线路 抗投诉全球[VPS测评]
- illyhosting→€3.55 月 1GB 内存 20GB SSD 虚拟空间(主机)
- WordPress插件:Simple URLs 链接点击统计管理全球[VPS测评]
- Porkbun域名注册优惠,.COM 仅 $4.75,.NET仅 $5.全球[VPS测评]
- AMHost bg → 保加利亚 2.5€月付 1C2G12G硬盘 不限全球[VPS测评]
- Shellrent → 黑五 7€月 一次性7折 1C1G20G硬盘 意全球[VPS测评]
- myvps.ru-俄罗斯 新加坡 日本 德国等 199卢布 月起日本VPS[主机]
- [谨慎]Tsukearu → 年付半价免初装费的日本小鸡 → 年付 ¥3日本VPS[主机]
- 新华全媒+丨第六届全球跨境电商大会:跨境电商加快拓宽中国贸易新通道全球[VPS测评]
- 性价比最高的VPS网络评测全球[VPS测评]
- 亿速云“双11”上云狂欢大促 高防云服务器、裸金属服务器优惠套餐全球[VPS测评]
- JGKVM:1核/512M/30G/600G/30Mbps/洛杉矶CN2全球[VPS测评]
- 极光kvm怎么样?香港大带宽VPS促销1核1G内存19元/月起,5G防御香港VPS[主机]
- PQhosting:香港HE/乌克兰/俄罗斯/荷兰/摩尔多瓦vps主机/香港VPS[主机]
- 香港云服务器的优势有哪些方面香港VPS[主机]
- 雪花云怎么样?雪花云香港云服务器1核1G2M仅19元/月香港VPS[主机]
- 硅云服务器拼团活动:香港云服务器1核1G,拼团价仅98元/年香港VPS[主机]
- 华为云香港企业级云服务器优惠:4核8G5M香港云服务器低至4764元/年香港VPS[主机]
- 尊云双十二:国内4核4G5M云服务器仅28元/月,香港CN2VPS仅84香港VPS[主机]
- 新华全媒+丨第六届全球跨境电商大会:跨境电商加快拓宽中国贸易新通道全球[VPS测评]
- uuuvps:香港大带宽vps低至239元/年;香港服务器720元/e3香港VPS[主机]
- 麻花云双12年终盛典:香港云主机9元起,老客户续费6折;安徽BGP线路v香港VPS[主机]
- 宝塔面板nginx中的网站如何添加身份验证?全球[VPS测评]
- edgeNAT:2021元旦vps促销_全场韩国/美国/香港VPS低至7韩国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-143591.html











