fail2banを導入した
CentOS 7
インストール
|
1 2 |
yum install epel-release yum install fail2ban |
設定
今回は例としてリファラーがexample.comだったらBANするという設定をしてみる。
まずはホワイトリストを登録する。
あくまでも例なので、適宜修正すること。
|
1 2 3 4 5 6 7 8 9 10 |
[DEFAULT] # # MISCELLANEOUS OPTIONS # # "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not # ban a host which matches an address in this list. Several addresses can be # defined using space (and/or comma) separator. ignoreip = 127.0.0.1/8 192.168.1.0/24 |
次にフィルターの設定をする。
/etc/fail2ban/filter.d/に新規ファイルを作成する。
|
1 2 |
[Definition] failregex = ^<HOST> .+"GET.+HTTP.+".+"https?://example\.com\..+" |
最後に/etc/fail2ban/jail.localでjailの設定をする。
|
1 2 3 4 5 6 |
[example] enabled = true maxretry = 1 # 1回目で即BAN bantime = 604800 # 1週間BANする port = http,https logpath = %(apache_access_log)s |
あとはfail2banを起動して自動起動の設定して終了。
|
1 2 |
systemctl start fail2ban systemctl enable fail2ban |