LoginSignup
49
40

fail2banの使い方

Last updated at Posted at 2021-02-07

最新記事は以下に記載しました。
fail2banの使い方

#1 fail2banとは?
不正アクセスからサーバを守るツールです。
具体的には、ログファイルに記録される内容を監視して、何度も認証に失敗しているログや、
連続アクセスしているログを見つけると、ファイアーウォールを自動的に調整して、
接続元からの不正アクセスを禁止にします。
たとえば、sshのログイン失敗すると、/var/log/secureに以下のログが記録されます。
fail2banは、このログを監視してsshログインに何度も失敗している接続元をアクセス禁止にします。

/var/log/secureの抜粋
Jan 31 20:58:45 server unix_chkpwd[127841]: password check failed for user (root)
Jan 31 20:58:45 server sshd[127839]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.2.105  user=root
Jan 31 20:58:47 server sshd[127839]: Failed password for root from 192.168.2.105 port 55770 ssh2

#2 環境
VMware Workstation 15 Player上の仮想マシン(2台)を使いました。
2台とも仮想マシンの版数は以下のとりです。

CentOSの版数
[root@server ~]# cat /etc/redhat-release
CentOS Linux release 8.3.2011
カーネル版数
[root@server ~]# uname -r
4.18.0-240.el8.x86_64

検証環境は以下のとおりです。
サーバで、fail2banを実行します。
クライアントでは、サーバに対してsshログインやcurlコマンドを実行します。

環境
              192.168.2.0/24
client --------------------------- server
    .120                        .115

#3 インストール方法

##3.1 fail2banのインストール
fail2banはepelリポジトリにあるので、まず、epel-releaseパッケージをインストールします。

epel-releaseのインストール
[root@server ~]# dnf -y install epel-release

次に、fail2banパッケージをインストールします。

fail2banのインストール
[root@server ~]# dnf -y install fail2ban

インストールしたfail2banの版数を確認します。

版数の確認
[root@server ~]# fail2ban-server --version
Fail2Ban v0.11.2
[root@server ~]# fail2ban-client --version
Fail2Ban v0.11.2
[root@server ~]# fail2ban-regex --version
fail2ban-regex 0.11.2
[root@server ~]# fail2ban-python --version
Python 3.6.8

##3.2 Apacheのインストール
サーバにApacheをインストールします。

インストール
[root@server ~]# dnf -y install httpd
49
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
49
40