MirrorNest
← すべてのガイド

Fail2ban

Fail2ban watches service log files for repeated authentication failures and automatically bans offending IPs via firewall rules, using per-service 'jails' you enable in jail.local.

このガイドは上記リンク先にあるFail2ban公式ドキュメントをもとに作成されています。ディストリビューションやプロジェクトのバージョンは時間とともに変わるため、本番サーバーでこれらのコマンドを実行する前に、必ず公式ドキュメントで正確なパッケージ名・バージョン名を確認してください。
  1. 1Install the package

    Fail2ban is already packaged for Debian/Ubuntu, which is the officially recommended way to install it rather than building from source.

    sudo apt update
    sudo apt install fail2ban
  2. 2Create a local jail configuration

    jail.conf is overwritten on updates — a jail.local override is the documented way to keep customizations safe.

    sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

    Edit jail.local to enable jails (e.g. [sshd]) and adjust bantime/findtime/maxretry.

  3. 3Enable and start the service

    sudo systemctl enable --now fail2ban
    sudo fail2ban-client status