大量に 404 エラーを出すホストを拒否(fail2ban)
大量に 404 エラーや 403 エラーを出すホストを、fail2ban で弾くことにしました。
フィルタの作成
フィルタを作成します。/etc/fail2ban/filter.d に 404, 403 用に、作成します。なお、Google と bing の bot は対象としないようにします。
apache-404.conf
[Definition] failregex = ^<HOST>.*"(GET|POST).*" (403|404) .*$ ignoreregex = ^<HOST>.*"(GET|POST).* (Googlebot|bingbot).*"$
アクセス制限の設定
/etc/fail2ba/jail.d に作成します。1日で 5 回エラーを出したホストを 60 日弾きます。ローカルネットワークは対象としません。
apache-404.conf
[apache-404] enabled = true port = http,https filter = apache-404 logpath = /var/log/apache2/*access.log action = iptables-multiport[name="http", port="http,https", protocol=tcp] ignoreip = 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 maxretry = 5 findtime = 86400 bantime = 5184000
fail2ban を再起動する
$ sudo service fail2ban restart
確認
$ sudo fail2ban-client status apache-404 Status for the jail: apache-404 |- Filter | |- Currently failed: 3 | |- Total failed: 4 | `- File list: /var/log/apache2/sirius10net_access.log /var/log/apache2/sirius10-ssl_access.log `- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list:
これでしばらく様子を見てみます。

ディスカッション
コメント一覧
まだ、コメントがありません