Fail2ban

如何檢查firewalld是否阻止傳入的IP地址?

  • January 27, 2021

我有帶防火牆的 CentOS 7。我安裝了 fail2ban 並使用了 firewallcmd-new 操作。我在 fail2ban 日誌中看到禁令,如果它們被阻止,我想檢查 firewallcmd。我該怎麼做?

首先,我強烈建議您使用banaction = firewallcmd-ipset,因為當禁止列表開始變大時,它會提供更好的性能。

現在,對於 fail2ban 的任何 firewalld 操作,它都會添加一個直接規則,您可以使用以下命令進行檢查firewall-cmd --direct --get-all-rules

# firewall-cmd --direct --get-all-rules
ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable
ipv4 filter INPUT 0 -p tcp -m multiport --dports 0:65535 -m set --match-set fail2ban-nginx-http-auth src -j REJECT --reject-with icmp-port-unreachable
ipv4 filter INPUT 0 -p tcp -m multiport --dports http,https -m set --match-set fail2ban-nginx-wordpress-login src -j REJECT --reject-with icmp-port-unreachable

如您所見,我使用的是firewallcmd-ipset,因此此處未列出實際被禁止的 IP 地址。相反,我發現它們是ipset list

# ipset list
Name: fail2ban-sshd
Type: hash:ip
Revision: 1
Header: family inet hashsize 1024 maxelem 65536 timeout 600
Size in memory: 16528
References: 1
Members:

Name: fail2ban-nginx-http-auth
Type: hash:ip
Revision: 1
Header: family inet hashsize 1024 maxelem 65536 timeout 600
Size in memory: 16528
References: 1
Members:

Name: fail2ban-nginx-wordpress-login
Type: hash:ip
Revision: 1
Header: family inet hashsize 1024 maxelem 65536 timeout 86400
Size in memory: 40656
References: 1
Members:
108.62.172.244 timeout 70819
108.62.172.121 timeout 82750
212.252.164.233 timeout 69907
108.62.24.87 timeout 58024
23.19.127.20 timeout 84310
### many more omitted...

引用自:https://serverfault.com/questions/751319