centos6/7系统安装fail2ban防CC攻击和SSH暴力破解

教程大全centos防CC,fail2ban

centos6/7系统安装fail2ban防CC攻击和SSH暴力破解
以下教程适合centos6和7系统,其他操作系统尚未尝试。

安装:

先安装epel源

  1. yum -y install epel-release

然后安装fail2ban

  1. yum -y install fail2ban

然后编辑配置文件/etc/fail2ban/jail.conf

  1. [DEFAULT]
  2. “ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
  3. # ban a host which matches an address in this list. Several addresses can be
  4. # defined using space separator.
  5. ignoreip = 127.0.0.1/8
  6. # External command that will take an tagged arguments to ignore, e.g. ,
  7. and return true if the IP is to be ignored. False otherwise.
  8. #
  9. # ignorecommand = /path/to/command
  10. ignorecommand =
  11. “bantime" is the number of seconds that a host is banned.
  12. bantime = 600
  13. # A host is banned if it has generated “maxretry" during the last “findtime"
  14. # seconds.
  15. findtime = 600
  16. “maxretry" is the number of failures before a host get banned.
  17. maxretry = 3
  18. “backend" specifies the backend used to get files modification.
  19. # Available options are “pyinotify"“gamin"“polling" and “auto".
  20. # This option can be overridden in each jail as well.
  21. #
  22. # pyinotify: requires pyinotify (a file alteration monitor) to be installed.
  23. # If pyinotify is not installed, Fail2ban will use auto.
  24. # gamin: requires Gamin (a file alteration monitor) to be installed.
  25. # If Gamin is not installed, Fail2ban will use auto.
  26. # polling: uses a polling algorithm which does not require external libraries.
  27. # auto: will try to use the following backends, in order:
  28. # pyinotify, gamin, polling.
  29. backend = auto
  30. “usedns" specifies if jails should trust hostnames in logs,
  31. # warn when DNS lookups are performed, or ignore all hostnames in logs
  32. #
  33. # yes: if a hostname is encountered, a DNS lookup will be performed.
  34. # warn: if a hostname is encountered, a DNS lookup will be performed,
  35. # but it will be logged as a warning.
  36. # no: if a hostname is encountered, will not be used for banning,
  37. # but it will be logged as info.
  38. usedns = warn

然后在/etc/fail2ban/jail.d目录新建jail.local文件,文件内容如下:

  1. [DEFAULT]
  2. “ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
  3. # ban a host which matches an address in this list. Several addresses can be
  4. # defined using space separator.
  5. ignoreip = 127.0.0.1/8,67.230.187.137,42.51.223.212,42.51.223.232,149.129.91.164,173.82.152.161
  6. # External command that will take an tagged arguments to ignore, e.g. ,
  7. and return true if the IP is to be ignored. False otherwise.
  8. #
  9. # ignorecommand = /path/to/command
  10. ignorecommand =
  11. “bantime" is the number of seconds that a host is banned.
  12. bantime = 600
  13. # A host is banned if it has generated “maxretry" during the last “findtime"
  14. # seconds.
  15. findtime = 600
  16. “maxretry" is the number of failures before a host get banned.
  17. maxretry = 3
  18. “backend" specifies the backend used to get files modification.
  19. # Available options are “pyinotify"“gamin"“polling" and “auto".
  20. # This option can be overridden in each jail as well.
  21. #
  22. # pyinotify: requires pyinotify (a file alteration monitor) to be installed.
  23. # If pyinotify is not installed, Fail2ban will use auto.
  24. # gamin: requires Gamin (a file alteration monitor) to be installed.
  25. # If Gamin is not installed, Fail2ban will use auto.
  26. # polling: uses a polling algorithm which does not require external libraries.
  27. # auto: will try to use the following backends, in order:
  28. # pyinotify, gamin, polling.
  29. backend = auto
  30. “usedns" specifies if jails should trust hostnames in logs,
  31. # warn when DNS lookups are performed, or ignore all hostnames in logs
  32. #
  33. # yes: if a hostname is encountered, a DNS lookup will be performed.
  34. # warn: if a hostname is encountered, a DNS lookup will be performed,
  35. # but it will be logged as a warning.
  36. # no: if a hostname is encountered, will not be used for banning,
  37. # but it will be logged as info.
  38. usedns = warn

完成后centos6系统输入以下命令启动

  1. service fail2ban restart

centos7系统输入以下命令启动

  1. systemctl restart fail2ban.service

设置centos6和centos7系统的开机启动

  1. CentOS 6:
  2. chkconfig fail2ban on
  3. CentOS 7:
  4. systemctl enable fail2ban

Posted by 柴郡猫