I am setting up fail2ban for my EC2 instances, each of which have different services running. Hence, I am configuring the jails specifically for each service. I have two questions (for which I could not find an answer elsewhere):
- If an IP gets blocked by fail2ban for failed authentication against one port, will that user still be able to get in through other open ports?
- How does blocking specific ports compare against blocking all ports using the configuration mentioned here? Wouldn't it be more secure to block all open ports since ultimately I do not want the hacker to get in?
(Assuming the OS is Linux)
fail2ban is a well made tool, blessed with a high level of configuration.
On Linux Ubuntu, the configuration is in
/etc/fail2ban
Question 1
Unless you change the configuration, only the port(s) mentioned in
jail.conf
for the particular service will be blocked.Question 2
You could also block all ports. It depends on the level of security you want, but blocking all ports can have drawbacks.
Personally, I prefer to block only the port that has been abused. Because
jail.conf
), they'll be blocked as wellssh
, you will prevent everybody on that address to accesshttp/s
for instancessh
, and another port that would allow a different access, from the provider for instance, won't be accessible.To block more, or all ports, you can modify the
jail.conf
file.Some of the default attributes are, (in
[DEFAULT]
)i.e., all ports.
For
[sshd]
for instance (and all services)port
is redefinedYou could simply comment out the
port
line to be back to the defaults, but I'd add a comment, and a new port line for easier maintenance (other people / you in 3 years)Changing the default
You will see in the
action.d
directory the list of possible actions. The default injail.conf
,that can also be changed to
that would affect all services not redefining
banaction
.Restarting fail2ban
Then restart the service, for systemd
or
(FYI, the
filter.d
directory lists for each service the way fail2ban detects an intrusion attempt)Check also the comments below that may provide valuable information.