Installing Fail2ban
To install the Fail2ban program, run the following commands:
- To install on Ubuntu, Debian:
sudo apt-get update
sudo apt-get install fail2ban
- To install on CentOS:
yum update
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install fail2ban
Definitions
Before you begin, it is important to clarify some of the terms used in the following sections:
- filter - filter defines a regular expression that should match a pattern matching a login error or any other expression
- action - action defines several commands that are executed at different points in time
- jail - jail (lit. English "prison") is a combination of one filter and one or more actions. Fail2ban can handle multiple filters at the same time
- client - refers to the fail2ban-client script
- server - refers to the fail2ban-server script
Server
Fail2ban consists of two parts: a client and a server. The server is multi-threaded and listens on a Unix socket for commands. The server itself knows nothing about configuration files. Thus, at startup, the server is in a "default" state where no jails are defined. The following options are available for the fail2ban server:
**-b** Start in the background
**-f** Start in front
**-s** Socket path
**-x** Force the server to run
**-h, —help** Display this help message
**-V, —version** Print version
Fail2ban-server should not be used directly except for debugging purposes. The -s
Fail2ban-client is an interface to Fail2ban. It connects to the server's socket file and sends commands to configure and control the server. The client can read configuration files or simply be used to send a single command to the server using the command line or interactive mode (which is activated with the -i option). fail2ban-client can also start the server. The following options are available for the fail2ban client:
**-c** Configuration directory
**-s** Socket path
**-d** Dump configuration. For debugging
**-i** Interactive mode
**-v** Increase verbosity
**—q** Decrease verbosity
**-x** Force the server to run
**-h, —help** Display this help message
**-V**, —version Print version
All settings in the configuration files can be configured manually. Configuration is a simple and effective way to set up a server. fail2ban-client translates the configuration into a set of commands. However, fail2ban-client has two more commands for internal use. The first is the start. When you enter the command $ fail2ban-client start - the client will first try to deploy a server instance. The client then waits for the server to start by sending it ping requests. Once the server responds to these requests, the fail2ban client parses the configuration and sends the appropriate commands to the server.
The second command is reboot. It is done by entering the command: $fail2ban-client reload
General settings
The fail2ban.conf file contains general settings for the fail2ban server daemon, such as logging level and target. Here you can also specify the socket path used for communication between the client and the server.