Difference between revisions of "CLI - fail2ban"

 
(7 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
{{note | Note that the fail2ban service blocks a client depending on its IP address. For example, Although a client whose IP address is 10.10.10.10 is blocking for the bantime, another client whose IP address is 20.20.20.20 can connect to the same device.}}
 
{{note | Note that the fail2ban service blocks a client depending on its IP address. For example, Although a client whose IP address is 10.10.10.10 is blocking for the bantime, another client whose IP address is 20.20.20.20 can connect to the same device.}}
 +
{{note | Note that directly connecting to the device console port is not affected by the fail2ban.}}
  
 
==== Verifying Current Configuration ====
 
==== Verifying Current Configuration ====
Line 15: Line 16:
 
fail2ban(ssh)                : active, bantime:5m, findtime:1m, maxretry:5
 
fail2ban(ssh)                : active, bantime:5m, findtime:1m, maxretry:5
 
</pre>
 
</pre>
{{note|Note that the above fail2ban configuration is the default. In other words, if you try to connect an imRAD device without knowing its password and you failed more than 5 times in one minute, your connection will be blocked for 5 minutes.
+
{{note|  
However, Accessing the device by connecting your PC directly to the switch console port is allowed.
+
Note that the above fail2ban configuration is the default. If you try to connect an imRAD device without knowing its password and you failed more than 5 times in one minute, your connection will be banned for 5 minutes.<br>
 +
In this case, Accessing the device by connecting your PC directly to the switch console port is allowed.
 
}}
 
}}
  
Line 23: Line 25:
 
<pre>
 
<pre>
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# fail2ban add 300 1800 10 // "bantime" is 300 seconds, "findtime" is 1800 seconds, and "maxtetry" is 10.
+
LYSH@MyHostName(config)# fail2ban add 300 1800 10 // "bantime" is 300 seconds, "findtime" is 1800 seconds, and "maxtetry" is 10.
configure# exit
+
LYSH@MyHostName(config)# exit
 
LYSH@MyHostName# show system fail2ban
 
LYSH@MyHostName# show system fail2ban
 
fail2ban(ssh)                : active, bantime:300, findtime:1800, maxretry:10  
 
fail2ban(ssh)                : active, bantime:300, findtime:1800, maxretry:10  
Line 33: Line 35:
 
<pre>
 
<pre>
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# fail2ban disable // disable the fail2ban service
+
LYSH@MyHostName(config)# fail2ban disable // disable the fail2ban service
configure# exit
+
LYSH@MyHostName(config)# exit
 
LYSH@MyHostName# show system fail2ban
 
LYSH@MyHostName# show system fail2ban
 
fail2ban(ssh)                : inactive, bantime:300, findtime:1800, maxretry:10  
 
fail2ban(ssh)                : inactive, bantime:300, findtime:1800, maxretry:10  
  
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# fail2ban enable // enable the fail2ban service
+
LYSH@MyHostName(config)# fail2ban enable // enable the fail2ban service
configure# exit
+
LYSH@MyHostName(config)# exit
 
LYSH@MyHostName# show system fail2ban
 
LYSH@MyHostName# show system fail2ban
 
fail2ban(ssh)                : active, bantime:300, findtime:1800, maxretry:10  
 
fail2ban(ssh)                : active, bantime:300, findtime:1800, maxretry:10  
 
</pre>
 
</pre>

Latest revision as of 10:47, 28 January 2022

fail2ban

Fail2ban is an intrusion prevention software framework that protects devices from brute-force attacks[1]. Fail2ban is typically set up to unban a blocked host within a certain period, so as to not "lock out" any genuine connections that may have been temporarily misconfigured. However, an unban time of several minutes is usually enough to stop a network connection being flooded by malicious connections, as well as reducing the likelihood of a successful dictionary attack.[2]

The primary purpose of fail2ban is to jail services. When a service, such as SSHd, is jailed, then fail2ban will continuously look in the log(s) of that service for possible repeated attempts. The moment that a given number (maxretry) of attempts is detected within a particular time window (findtime) then a blocking rule (such as through iptables) is automatically set for a given time period (bantime).[3]

Fail2ban configuration has three terms. The first is "bantime" which indicates the time a host will be blocked. The second is "findtime" which is the length of time between login attempts before a ban is set. The last is "maxretry" which indicates how many attempts can be made to access the server before a ban is imposed. If a client is banned, the client can't connect to a device.

Note that the fail2ban service blocks a client depending on its IP address. For example, Although a client whose IP address is 10.10.10.10 is blocking for the bantime, another client whose IP address is 20.20.20.20 can connect to the same device.

Note that directly connecting to the device console port is not affected by the fail2ban.

Verifying Current Configuration

If you want to verify the current configuration, enter the show system fail2ban. The result shows

LYSH@MyHostName# show system fail2ban
fail2ban(ssh)                 : active, bantime:5m, findtime:1m, maxretry:5

Note that the above fail2ban configuration is the default. If you try to connect an imRAD device without knowing its password and you failed more than 5 times in one minute, your connection will be banned for 5 minutes.
In this case, Accessing the device by connecting your PC directly to the switch console port is allowed.

Configuring the fail2ban

You can configure the fail2ban in the configuration mode. enter the fail2ban add <bantime> <findtime> <maxtetry> in the configuration mode. The "bantime" and "findtime" is in seconds.

LYSH@MyHostName# configure
LYSH@MyHostName(config)# fail2ban add 300 1800 10	// "bantime" is 300 seconds, "findtime" is 1800 seconds, and "maxtetry" is 10.
LYSH@MyHostName(config)# exit
LYSH@MyHostName# show system fail2ban
fail2ban(ssh)                 : active, bantime:300, findtime:1800, maxretry:10 

Enable / Disable the fail2ban

If you do not want to fail2ban service, enter fail2ban disable in the configuration mode. Also you can enable it.

LYSH@MyHostName# configure
LYSH@MyHostName(config)# fail2ban disable		// disable the fail2ban service
LYSH@MyHostName(config)# exit
LYSH@MyHostName# show system fail2ban
fail2ban(ssh)                 : inactive, bantime:300, findtime:1800, maxretry:10 

LYSH@MyHostName# configure
LYSH@MyHostName(config)# fail2ban enable		// enable the fail2ban service
LYSH@MyHostName(config)# exit
LYSH@MyHostName# show system fail2ban
fail2ban(ssh)                 : active, bantime:300, findtime:1800, maxretry:10