What Does a Freshly Deployed Server Face Online?
Within minutes of getting a public IP, a new VPS inevitably receives uninvited guests. Real-world statistics show that a server with port 22 open typically faces between 2,000 and over 10,000 scans daily from botnets. They relentlessly test common credential pairs like root/admin, ubuntu/123456, or test/password.
This automated probing technique is known as a brute-force attack. No matter how complex your password is, letting bots spam thousands of connection attempts every hour wastes valuable resources. CPU usage spikes, bandwidth is consumed, and system log files can balloon to several gigabytes in just a week.
The most effective solution is to automatically shut the door on suspicious IPs. Fail2ban, combined with Fedora’s default firewalld firewall, does exactly that.
How Fail2ban and firewalld Work Together
This duo operates under a clear division of responsibilities:
- Fail2ban acts as the monitor: This daemon continuously watches system authentication logs. If an IP fails to log in too many times within a set timeframe, Fail2ban immediately blacklists it.
- firewalld acts as the enforcer: Fail2ban does not manipulate network traffic directly. Instead, it instructs
firewalldto add a rich rule that drops packets from the offending IP.
By pushing packet filtering down to the Linux kernel’s Netfilter layer via firewalld, the server expends virtually no CPU cycles to reject malicious connections.
Step-by-Step Installation and Configuration
Fedora Server always ships with cutting-edge software packages from the Red Hat ecosystem. Setup takes only about 5 minutes across the 5 steps below.
Step 1: Install Fail2ban and the firewalld Integration Package
By default, firewalld is pre-installed on Fedora Server. You only need to install Fail2ban along with its dedicated integration package:
sudo dnf install -y fail2ban fail2ban-firewalld
The fail2ban-firewalld package is particularly crucial. It automatically loads the configuration template enabling Fail2ban to manage firewalld via rich rules, rather than injecting fragmented iptables rules directly into the system.
Step 2: Create a Minimal Configuration File (jail.local)
Many guides suggest copying the entire jail.conf file to jail.local. This leaves you with hundreds of lines of configuration, making package updates difficult to manage. The best practice is to create a clean /etc/fail2ban/jail.local file containing only the directives you want to override:
sudo nano /etc/fail2ban/jail.local
Paste the following general configuration into the file:
[DEFAULT]
# Whitelist your static IP or local subnet
ignoreip = 127.0.0.1/8 ::1 192.168.1.0/24
# Ban duration (e.g., 1h, 1d, 1w)
bantime = 1h
# Time window to count failed attempts (10 minutes)
findtime = 10m
# Maximum number of failed attempts before being banned
maxretry = 3
# Use firewalld as the enforcement action
banaction = firewallcmd-rich-rules
Step 3: Enable Monitoring for the SSH Service
Still inside /etc/fail2ban/jail.local, add the configuration block for SSH at the bottom:
[sshd]
enabled = true
port = ssh
backend = systemd
Unlike Ubuntu or Debian which store logs in /var/log/auth.log, Fedora uses systemd-journald for log management. The backend = systemd parameter enables Fail2ban to read authentication events directly from journald in memory, making it faster and independent of plain text log files.
Step 4: Start and Verify the Service
Enable Fail2ban to start on boot and launch it immediately:
sudo systemctl enable --now fail2ban
Once the service is running, use the CLI tool to check the status of the sshd jail:
sudo fail2ban-client status sshd
You should see output similar to this:
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:
Step 5: Test the Setup and Unban an IP When Needed
Test the jail by tethering to your mobile data and attempting to SSH into the server with an incorrect password 3 times consecutively. On the 4th attempt, the connection should either hang or be refused immediately.
On the server, check the updated blacklist:
sudo fail2ban-client status sshd
To view the active firewall drop rule at the firewall layer, run:
sudo firewall-cmd --list-rich-rules
The system will return a rule like: rule family="ipv4" source address="203.0.113.45" port port="ssh" protocol="tcp" reject type="icmp-port-unreachable".
If you or a colleague accidentally enter the wrong password and get locked out, run the following command to unban the IP immediately:
sudo fail2ban-client set sshd unbanip 203.0.113.45
Additional Tips for Server Hardening
Fail2ban is an effective safeguard when running a publicly accessible SSH port. However, it only treats the symptom of brute-force scanning. For robust security, you should disable password authentication entirely (PasswordAuthentication no) and switch exclusively to SSH keys using the Ed25519 algorithm. Combining both approaches makes your server virtually impervious to automated attacks.

