CentOS 7にfail2banをインストールしたのですが、うんともすんともいいません。 🙁
いろいろ調べた結果、なんとか動かすことが出来たので、解決策やfail2banの仕組みなどをメモっておきます。
fail2banの設定ファイル
/etc/fail2ban/jail.confに基本的な設定事項が書かれている。
/etc/fail2ban/jail.localは、jail.confに書かれた設定を上書きする。
sshdの不正アクセスを監視するときは、jail.confの以下の部分のコメントをはずす。
(修正前)
# [sshd] # enabled = true
↓
[sshd] enabled = true
/etc/fail2ban/filter.d/sshd.confの『failregex = 』の行(64行目付近)に赤文字の行を追加する。
failregex = %(mode)s
^%(__prefix_line)sConnection closed by \[preauth\]$
※このファイルをどのようなフォーマットで書けばいいのかが不明。
とりあえず、『%(mode)s』と頭を揃えておけばよさそうだ。
起動/停止/再起動/自動起動
■起動
# systemctl start fail2ban
■停止
# systemctl stop fail2ban
■再起動
# systemctl restart fail2ban
■自動起動
# systemctl enable fail2ban
■自動起動解除
# systemctl disable fail2ban
参考記事
CentOS7 fail2banについて
不正アクセスからサーバを守るfail2ban。さくらのクラウド、VPSで使ってみよう!
CentOS7 fail2banでSSH, SMTPへの攻撃からサーバを守る