セキュリティ対策 - fail2ban - 初期設定


クラウディア 


1. 概要
2. デフォルトの設定
3. 起動
4. 参考サイト

1. 概要

 最低限の設定でも、起動だけはできるようです。

2. デフォルトの設定

 デフォルトの設定は。

/usr/local/etc/fail2ban/jail.conf
 に書いてあります。  このファイルは、将来のバージョンアップ時に自動更新される可能性があるらしく、これを編集することはないらしい。  全文掲載しようと思いましたが、992行もあるので、主な個所だけピックアップして掲載します。

[INCLUDES]

#before = paths-distro.conf
before = paths-freebsd.conf

# "bantime" is the amount of time that a host is banned, integer in seconds or
# time abbreviation format (m - minutes, h - hours, d - days, w - weeks, mo - months, y - years).
# This is to consider as an initial time if bantime.increment gets enabled.
bantime  = 10m

# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime  = 10m

# "maxretry" is the number of failures before a host get banned.
maxretry = 5
 「bantime」「findtime」「maxretry」

# Destination email address used solely for the interpolations in
# jail.{conf,local,d/*} configuration files.
destemail = root@localhost

# Sender email address used solely for some actions
sender = root@<fq-hostname>

# E-mail action. Since 0.8.1 Fail2Ban uses sendmail MTA for the
# mailing. Change mta configuration parameter to mail if you want to
# revert to conventional 'mail'.
mta = sendmail
 「destemail」「sender」「mta」  つまり、「FreeBSD」であるからには、「FreeBSD」の設定をインクルードするわけですな。  同じディレクトリにある「paths-freebsd.conf」は、短いので、掲載しても構わんかな。

# FreeBSD

[INCLUDES]

before = paths-common.conf

after  = paths-overrides.local


[DEFAULT]

# http://www.freebsd.org/doc/handbook/configtuning-syslog.html
#
syslog_mail = /var/log/maillog

syslog_mail_warn = /var/log/maillog

# note - is only ftp.info - if notice /var/log/messages may be needed
syslog_ftp = /var/log/xferlog

# Linux things

# http://svnweb.freebsd.org/ports/head/www/apache24/files/patch-docs__conf__extra__httpd-ssl.conf.in?view=markup
# http://svnweb.freebsd.org/ports/head/www/apache22/files/patch-docs__conf__extra__httpd-ssl.conf.in?view=markup
# http://svnweb.freebsd.org/ports/head/www/apache24/files/patch-config.layout
# http://svnweb.freebsd.org/ports/head/www/apache22/files/patch-config.layout

apache_error_log = /var/log/httpd-error.log

apache_access_log = /var/log/httpd-access.log

# http://svnweb.freebsd.org/ports/head/www/nginx/Makefile?view=markup

nginx_error_log = /var/log/nginx/error.log

nginx_access_log = /var/log/nginx/access.log
 と、「FreeBSD」でのデフォルトのログパスが記述してあります。  (わたしの場合、これも変えてあるので、何かと編集せにゃならんな)

3. 起動

 「root」ユーザ権限で。  「fail2ban」の起動を有効にして。

sysrc fail2ban_enable="YES"
 起動。

service fail2ban start

Server ready
 起動状態は。

service fail2ban status

fail2ban is running as pid 11575.
 でも見られますが、詳細は。

fail2ban-client status
 で見ます。  何もいじらないうちに見てみたら。

Status
|- Number of jail:      0
`- Jail list:
 「fail2ban」のログは、デフォルトで。

/var/log/fail2ban.log
 に出来るようで、上記の初回起動後に下記が出力されておりました。

2026-02-27 11:04:44,397 fail2ban.server         [11575]: INFO    --------------------------------------------------
2026-02-27 11:04:44,397 fail2ban.server         [11575]: INFO    Starting Fail2ban v1.1.0
2026-02-27 11:04:44,398 fail2ban.server         [11575]: INFO    Daemon started
2026-02-27 11:04:44,399 fail2ban.observer       [11575]: INFO    Observer start...
2026-02-27 11:04:44,436 fail2ban.database       [11575]: INFO    Connected to fail2ban persistent database '/var/db/fail2ban/fail2ban.sqlite3'
2026-02-27 11:04:44,475 fail2ban.database       [11575]: WARNING New database created. Version '4'

4. 参考サイト

 本ページは、下記のサイトおよび「Gemini」伍長を参考にさせていただきました。
FreeBSD 14 : Fail2Ban : 侵入防止システム

TikTok Shop 【リピート用プログラム】
AbemaTV 無料体験