外部からの執拗なアタックを軽減させるツール
本家様 https://www.fail2ban.org/wiki/index.php/Main_Page
sshサーバへのddosアタックらを軽減できるみたい. 他にもwebサイトへのF5アタックとか.
本家様でも書かれているが、これを仕込んでもssh接続が安全になるわけではない.
sshd_configの「PasswordAuthentication yes」(/etc/passwdでも認証ok)を「PasswordAuthentication no」として
公開鍵を作ってより効果的にすべきかと.
インストール †
[root@c ~]# yum install epel-release
[root@c ~]# yum install fail2ban-server fail2ban-sendmail fail2ban-firewalld fail2ban fail2ban-systemd.noarch
設定方法 †
「/etc/fail2ban/jail.conf」に
# Changes: in most of the cases you should not modify this
# file, but provide customizations in jail.local file,
# or separate .conf files under jail.d/ directory, e.g.:
とあるので「/etc/fail2ban/jail.local」を新規作成します。
方針としては ssh のみ防げばいいので
[sshd]
enabled = true
logpath = /var/log/ssh.log # 普通なら /var/log/secureですが、ここではsshdの出力を分けているので
[DEFAULT]
ignoreip = 127.0.0.1/8 192.168.0.0/24
bantime = ???? #数字が入ってます
findtime = ???? #数字が入ってます
maxretry = ??? #数字が入ってます
とする。
そして下記のようにして起動する
[root@c ~]# systemctl enable fail2ban.service
[root@c ~]# systemctl start fail2ban.service
動作確認 †
運用後暫くすればBanされた方々が下記コマンドで見れます。
[root@c ~]#
[root@c ~]# fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 5308
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
`- Actions
|- Currently banned: 24
|- Total banned: 2578
`- Banned IP list: <BanされたIPアドレスが列挙されます>
[root@c ~]#
CentOS8 †
systemd-tmpfiles[13104]: [/usr/lib/tmpfiles.d/fail2ban.conf:1] Line references path below legacy directory /var/run/, updating /var/run/fail2ban → /run/fail2ban; please update the tmpfiles.d/ drop-in file accordingly.