转载注明来源: 本文链接 来自osnosn的博客,写于 2020-11-7.
apt install fail2ban
debian-10 安装后,默认就已经"激活" 并 "启动"
创建 /etc/fail2ban/filter.d/nginx-MyRule.local (按需。如果你不需要,就不用创建)
这是自定义的nginx访问的规则。
目的是阻止网页的扫描,如果有大量访问"文件不存在的页面",就禁了他。
[INCLUDES]
#before = botsearch-common.conf
[Init]
block = \/?(
webmail = roundcube|(ext)?mail|horde|(v-?)?webmail
phpmyadmin = (typo3/|xampp/|admin/|)(pma|(php)?[Mm]y[Aa]dmin)
wordpress = wp-(login|signup|admin).php
[Definition]
failregex = ^
^
ignoreregex =
datepattern = {^LN-BEG}%%ExY(?P<_sep>[-/.])%%m(?P=_sep)%%d[T ]%%H:%%M:%%S(?:[.,]%%f)?(?:\s%%z)?
^[^[][({DATE})
{^LN-BEG}
创建 /etc/fail2ban/jail.local
[sshd]
enabled = true
port = 22,2222
#ignoreip=127.0.0.1/8 192.168.0.0/16
ignoreip=127.0.0.1/8
findtime=300
maxretry=10
bantime=1800
[nginx-MyRule]
enabled = true
port = http,https,10443
logpath = %(nginx_access_log)s
ignoreip = 127.0.0.1/8
maxretry = 30
findtime = 1200
bantime = 14400
重启 service fail2ban reload
fail2ban 启动后不会马上在iptables中创建规则。所以这时去看防火墙规则,是没有变化的。要等到需要deny时,才动态创建的。
如果满足ban规则,因为 debian-10 默认是用 iptables/ip6tables 指令。
INPUT
,跳转到f2b-sshd。Chain f2b-sshd
中插入对应ipv4的deny规则。Chain f2b-sshd
中插入对应ipv6的deny规则。table ip(6) filter { chain INPUT { ... } }
跳转f2b-sshd。table ip(6) filter { chain f2b-sshd { ... } }
。dnf install fail2ban
其他配置,和 debian-10 相同。
centos-8 安装后,没有"激活" 和 "启动", 所以需要手工激活/启动。
systemctl enable fail2ban; systemctl start fail2ban
fail2ban 启动后不会在nft中创建规则。所以nft中看不到变化。要等到需要deny时,才会在nft中添加rule。
如果满足ban规则,因为 centos-8 默认是用 nft 做防火墙。
table inet firewalld { chain filter_IN_public_deny { ... } }
插入deny规则。手机扫一扫
移动阅读更方便
你可能感兴趣的文章