
CentOS 8 で、ssh と Nginx が構成された fail2ban を実行しています。fail2ban-client status を実行すると、両方の IP がブロックされていると表示されますが、実際には、firewalld によってブロックされているわけではありません。ssh 攻撃が集中していますが、ファイアウォール側では何も起きていません。「tcpdump - i any port 80 or port 443 or port 22」を実行すると、複数の試行が失敗しています。fail2ban は再びそれらを認識し、禁止されていると表示しますが、実際には禁止されていません。何か提案はありますか?
[DEFAULT]
ignoreip = 127.0.0.1 192.168.1.0/24
bantime = 21600
findtime = 300
maxretry = 3
banaction = iptables-multiport
backend = systemd
[sshd]
enabled = true
[nginx-http-auth]
enabled = true
filter = nginx-http-auth
port = http,https
logpath = /var/log/gitlab/nginx/error.log
[nginx-noscript]
enabled = true
port = http,https
filter = nginx-noscript
logpath = /var/log/gitlab/nginx/access.log
maxretry = 6
[nginx-badbots]
enabled = true
port = http,https
filter = nginx-badbots
logpath = /var/log/gitlab/nginx/access.log
maxretry = 2
[nginx-nohome]
enabled = true
port = http,https
filter = nginx-nohome
logpath = /var/log/gitlab/nginx/access.log
maxretry = 2
[nginx-noproxy]
enabled = true
port = http,https
filter = nginx-noproxy
logpath = /var/log/gitlab/nginx/access.log
maxretry = 2
[gitlab]
enabled = true
port = http,https
filter = gitlab
logpath = /var/log/gitlab/gitlab_error.log
答え1
banaction
実際にfirewalldを使用している場合は、などのfirewalld互換のものを使用するようにしてくださいfirewallcmd-ipset
。
答え2
特に fail2ban-client status sshd の出力に IP がリストされている場合、設定は適切です。
IP が禁止されているかどうかをどのように確認していますか? これは、私が管理しているシステムで IP が禁止されているかどうかを確認する方法です。
iptables -L f2b-sshd
Chain f2b-sshd (1 references)
target prot opt source destination
REJECT all -- 120.29.125.240 anywhere reject-with icmp-port-unreachable
RETURN all -- anywhere anywhere
そこにリストされていない場合は、禁止と禁止解除があまりにも早く行われているだけでしょうか? 設定が 6 時間に設定されており、十分な長さであるはずです。
それができない場合は、/var/log/fail2ban.log で関連するアクティビティを確認することもできます。例:
2020-12-04 09:17:07,590 fail2ban.filter [9089]: INFO [sshd] Found 120.29.125.240
2020-12-04 09:17:09,883 fail2ban.filter [9089]: INFO [sshd] Found 120.29.125.240
2020-12-04 09:17:12,163 fail2ban.filter [9089]: INFO [sshd] Found 120.29.125.240
2020-12-04 09:17:14,381 fail2ban.filter [9089]: INFO [sshd] Found 120.29.125.240
2020-12-04 09:17:16,874 fail2ban.filter [9089]: INFO [sshd] Found 120.29.125.240
2020-12-04 09:17:17,805 fail2ban.actions [9089]: NOTICE [sshd] Ban 120.29.125.240