| Works
fail2banの設定をCentOS 7でやり直し
先月のサーバ移行の残作業。
CMSのログオンページに対する不審なアクセスを遮断する設定は同じだけど、fail2banの初期設定がだいぶ異なっていたので備忘録。
(CentOS 6と同じ設定でも動くは動くけど)
fail2banはepelから"yum"でインストール。
"/etc/fail2ban/filter.d"の下にフィルタファイルを作成するまでは一緒。
以前は"/etc/fail2ban/jail.conf"にアクションを追記していたのですが、今回はこのファイルには手をつけずに、"/etc/fail2ban/jail.d/jail.local"ファイルを作成して下記の内容を記述。
[DEFAULT]
banaction = firewallcmd-ipset
destemail = notice@example.com
sender = fail2ban@example.com
[apache-weblogin]
enabled = true
filter = apache-weblogin
port = http,https
logpath = /var/log/httpd/ssl-access_log
action = %(action_mw)s
bantime = 3600
maxretry = 3
今回の環境はファイアウォール設定にfirewalldを使っているので、既定の値として"banaction = firewallcmd-ipset"を指定。
"action = %(action_mw)s"については"jail.conf"の中で下記のように定義されている(該当箇所のみ抜粋)。
# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
%(mta)s-whois[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]
あとはサービスを起動と自動起動の有効化をして完了。
# systemctl start fail2ban.service
# systemctl enable fail2ban.service
fail2banの状態は"fail2ban-client status <フィルタ名>"コマンドで確認する。
# fail2ban-client status apache-weblogin
Status for the jail: apache-weblogin
|- Filter
| |- Currently failed: 0
| |- Total failed: 3
| `- File list: /var/log/httpd/ssl-access_log
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:
こんな所でしょうか。