Centos
fail2ban 應用禁令但沒有阻止連接
我
sshd
在 CentOS 上啟用了 fail2ban 設置。它正在閱讀日誌。使用 SSH 從遠端伺服器登錄失敗進行一些測試:Nov 23 20:51:52 new fail2ban.filter[29090]: INFO [sshd] Found 199.180.250.xx Nov 23 20:51:55 new fail2ban.filter[29090]: INFO [sshd] Found 199.180.250.xx Nov 23 20:51:58 new fail2ban.filter[29090]: INFO [sshd] Found 199.180.250.xx Nov 23 20:52:07 new fail2ban.filter[29090]: INFO [sshd] Found 199.180.250.22 Nov 23 20:52:07 new fail2ban.actions[29090]: NOTICE [sshd] 199.180.250.xx already banned Nov 23 20:52:10 new fail2ban.filter[29090]: INFO [sshd] Found 199.180.250.xx Nov 23 20:52:13 new fail2ban.filter[29090]: INFO [sshd] Found 199.180.250.xx
即使在禁令之後,似乎也允許連接。我查看了 iptables,它看起來是正確的:
Chain f2b-sshd (1 references) target prot opt source destination REJECT all -- 199.180.250.xx 0.0.0.0/0 reject-with icmp-port-unreachable RETURN all -- 0.0.0.0/0 0.0.0.0/0
連接不是持久的。遠端伺服器仍然可以打開到這個執行 fail2ban 的伺服器的 SSH 會話。
我還缺少什麼?
完整的iptables:
Chain INPUT (policy ACCEPT) target prot opt source destination f2b-sshd-ddos tcp -- 0.0.0.0/0 0.0.0.0/0 multiport dports 22 f2b-sshd tcp -- 0.0.0.0/0 0.0.0.0/0 multiport dports 22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:200xyz flags:0x17/0x02 Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain f2b-sshd (1 references) target prot opt source destination REJECT all -- 199.180.250.xx 0.0.0.0/0 reject-with icmp-port-unreachable RETURN all -- 0.0.0.0/0 0.0.0.0/0 Chain f2b-sshd-ddos (1 references) target prot opt source destination RETURN all -- 0.0.0.0/0 0.0.0.0/0
在配置中,
port = ssh
必須更改為自定義 SSH 埠。我曾假設 Linux 會知道 SSH 埠的定義,而 fail2ban 會遵循該系統配置,但我錯了。