If a server is exposed to the net, attackers can scan that server for as several vulnerabilities as attainable. That’s simply a part of running a server - therefore however will we manage these attacks? Fail2Ban is a necessary tool for server directors. Fail2Ban works by scanning logs and police work patterns in them, interference informatics addresses UN agency try malicious activities (continual unsuccessful logins, mass logins, etc). This guide can detail a way to tack together Fail2Ban on a server running CentOS half dozen or Debian Wheezy.
Protect SSH from fail2ban
On Debian seven, run:
#sudo apt-get update && sudo apt-get install fail2ban
On CentOS half dozen, run:
# rev -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm && yum install fail2ban
Fail2Ban’s configuration file is found in /etc/fail2ban/jail.conf. within the event one thing breaks with the configuration file once we edit it, we should always have a backup of the initial copy handy.
# cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.conf.bak
Open the configuration file:
# nano /etc/fail2ban/jail.conf
This is the default configuration file:
# "ignoreip" are often AN informatics address, a CIDR mask or a DNS host. Fail2ban won't
# ban a bunch that matches AN address during this list. many addresses are often
# outlined victimization area centrifuge.
ignoreip = 127.0.0.1
# "bantime" is that the range of seconds that a bunch is illegal.
bantime = 3600
# a bunch is illegal if it's generated "maxretry" throughout the last "findtime"
findtime = 600
# "maxretry" is that the range of failures before a bunch get illegal.
maxretry = three
Enter all informatics addresses you would like to grant immunity from Fail2Ban. All desired informatics addresses and ranges ought to be separated by one area, as shown below.
ignoreip = 127.0.0.1 22.214.171.124 2604:0180::/48
Now, we have a tendency to select bantime, findtime, and maxretry values. bantime refers to the length of the ban against AN informatics or vary initiated by Fail2Ban. notice time sets the grace amount for a user, in different words, however long every unsuccessful login try counts as a strike against AN informatics. maxretry tells Fail2Ban what number unsuccessful login makes an attempt a user is given before they're illegal.
To restart Fail2Ban, run the subsequent command:
# sudo service fail2ban restart
Your server is currently protected by Fail2Ban.