Harden Ubuntu with Fail2ban and UFW (Southbank Case Study)
Lock down SSH and open ports on Ubuntu with UFW and Fail2ban. Practical fixes for ban loops, blocked admins, and noisy jails—plus when remote server support from Fixwebnode makes sense.
If your Ubuntu server in Southbank or elsewhere is exposed to the internet, unfiltered SSH and open ports invite brute-force noise within hours. This guide walks homeowners and small businesses through hardening with UFW and Fail2ban: real package names, copy-pasteable commands, verification steps, and three distinct failure modes you can fix yourself before booking remote help.
Scope assumes Ubuntu 22.04 or 24.04 LTS with sudo access, OpenSSH, and a public IP or cloud VPS. Fixwebnode provides direct server support for this exact stack—configuration review, jail tuning, and recovery when a lockout blocks your own login—not a freelance marketplace.
Why Fail2ban and UFW matter for Ubuntu server hardening
UFW (Uncomplicated Firewall) is the standard front-end to iptables/nftables on Ubuntu. It defaults to deny incoming, allow outgoing, and lets you open only what you need (typically 22/tcp for SSH, 80/443 for web). Fail2ban watches auth logs, matches repeated failures, and inserts temporary bans so scanners stop hammering your host.
Together they cut noise, reduce successful brute-force risk, and give you clear logs when something goes wrong. Teams running sites or small business apps near Southbank often leave default SSH open with password auth and no rate limit—exactly the pattern these tools correct. Geography for on-site or hybrid work is listed under all service areas; most of this work is remote over SSH or a break-glass console.
How do I stop Fail2ban from locking me out while still blocking SSH attacks?
Whitelist your static admin IP in Fail2ban and UFW, use key-based SSH, and keep a short ban time while you tune filters. If you already locked yourself out, use your cloud provider console or a secondary network path to remove the ban and add ignoreip before re-enabling the jail.
| Symptom | Quick fix | When to call Fixwebnode |
|---|---|---|
| Your IP banned after failed logins | Unban via console; add ignoreip | No console access or recurring lockouts |
| UFW blocks needed service ports | Allow by port/app; reload; verify status | Complex multi-host or VPN rules |
| Jail never bans attackers | Check filter, log path, failregex | Custom apps or non-standard logs |
Common issues when securing Ubuntu with Fail2ban and UFW
These problems show up repeatedly on freshly deployed or lightly maintained Ubuntu hosts. Each has a different root cause.
- Admin lockout after Fail2ban ban — You (or a CI runner) hit maxretry; SSH drops mid-session or new connections refuse with timeout. Symptom:
Connection timed outfrom your office IP while the server still pings. - Legitimate services unreachable after UFW enable — Enabling UFW without allowing HTTP/HTTPS or app ports first. Symptom: site 504/connection refused;
ufw statusshows only OpenSSH. - Fail2ban jail active but zero bans — Wrong logfile path, disabled jail, or filter that never matches. Symptom:
fail2ban-client status sshdshows Currently banned: 0 despite auth.log full of failures. - Ban list grows forever / disk or conntrack pressure — Long bantime, no findtime tuning, or recidive jail misconfigured. Symptom: slow networking, huge iptables chains, or fail2ban using unexpected CPU.
Fix 1 — Recover from Fail2ban admin lockout and whitelist safely
Root cause: your public IP was not in ignoreip, and repeated key or password failures triggered the sshd jail. DIY is safe if you still have cloud serial/VNC console or another allowed network path.
Step 1 — Confirm the ban from an alternate path
Log in via your provider’s web console (not the banned IP). Then run:
sudo fail2ban-client status sshd
sudo fail2ban-client get sshd banipNote your public IP if it appears in the banned list.
Step 2 — Unban your IP immediately
sudo fail2ban-client set sshd unbanip YOUR.PUBLIC.IP.HEREReplace with your real IPv4. Test SSH from your workstation right away.
Step 3 — Whitelist admin and office ranges permanently
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.localUnder [DEFAULT], set something like:
[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 YOUR.PUBLIC.IP.HERE 203.0.113.0/24
bantime = 1h
findtime = 10m
maxretry = 5Use your real static IPs or office CIDR only—never 0.0.0.0/0.
Step 4 — Restart and verify
sudo systemctl restart fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshdYou should see the jail active and your IP absent from the ban list. Prefer SSH keys and disable password auth once stable:
sudo nano /etc/ssh/sshd_config
# PasswordAuthentication no
# PermitRootLogin no
sudo systemctl reload sshWhen to book Fixwebnode: no console access, dynamic home IPs that keep changing, or lockouts tied to reverse proxies and non-SSH jails. Remote recovery is available via server support.
Fix 2 — Restore services blocked after enabling UFW
Root cause: ufw enable was run before application allow rules, so only the SSH profile (or nothing) remained open. Distinct from Fail2ban: packets never reach the daemon.
Step 1 — Inspect current rules without dropping SSH
sudo ufw status verbose
sudo ufw status numberedIf you are already locked out of the app ports but still on SSH, continue. If SSH itself is blocked, use the provider console and:
sudo ufw allow OpenSSH
sudo ufw reloadStep 2 — Allow required application traffic
Typical web host:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw default deny incoming
sudo ufw default allow outgoingIf you use Nginx/Apache app profiles:
sudo ufw app list
sudo ufw allow 'Nginx Full'
# or: sudo ufw allow 'Apache Full'For a database only reachable from an app subnet (example):
sudo ufw allow from 10.0.0.0/24 to any port 5432 proto tcpStep 3 — Enable or reload and verify
sudo ufw --force enable
sudo ufw reload
sudo ufw status verbose
sudo ss -tulpnConfirm listeners match allowed ports. From an external host:
curl -I https://YOUR.DOMAIN
nc -vz YOUR.SERVER.IP 443Step 4 — Order rules carefully if you use denies
Numbered deletes help when a broad deny sits above an allow:
sudo ufw status numbered
sudo ufw delete 3Re-add the correct allow, then reload.
When to book Fixwebnode: multi-interface hosts, WireGuard/VPN coexistence, or production cutovers where a wrong rule means downtime. Southbank and wider Melbourne remote work is covered; see also Southbank 3006 VIC support for local context and custom business software development in Cremorne & Docklands when app deployment and firewall policy must stay aligned.
Fix 3 — Make Fail2ban actually ban (sshd jail silent)
Root cause: jail not enabled in jail.local, backend/logpath mismatch on Ubuntu’s journald setup, or a filter that does not match your SSH log lines. Different from lockout: attackers are never banned.
Step 1 — Confirm package and service health
sudo apt update
sudo apt install -y fail2ban ufw
sudo systemctl enable --now fail2ban
sudo systemctl status fail2ban --no-pagerStep 2 — Enable the sshd jail explicitly
sudo nano /etc/fail2ban/jail.localEnsure:
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
maxretry = 5
findtime = 10m
bantime = 1hOn modern Ubuntu, the default paths usually resolve via fail2ban’s paths-debian.conf. Force journald if needed:
[sshd]
enabled = true
backend = systemd
journalmatch = _SYSTEMD_UNIT=ssh.service + _COMM=sshdStep 3 — Validate filter against real log lines
sudo journalctl -u ssh --since "1 hour ago" | tail -n 50
sudo fail2ban-regex systemd-journal /etc/fail2ban/filter.d/sshd.confOr against a file log:
sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.confYou want a non-zero count of matched failure lines. If zero, your log format or path is wrong—fix backend/logpath before inventing custom failregex.
Step 4 — Reload and simulate a controlled test
sudo fail2ban-client reload
sudo fail2ban-client status sshdFrom a non-whitelisted test IP (not your only admin path), generate a few failed logins, then re-check:
sudo fail2ban-client status sshd
sudo tail -n 30 /var/log/fail2ban.logExpect “Ban” lines and a rising Currently banned count. Unban the test IP when done.
When to book Fixwebnode: custom panels, non-SSH jails (Proxmox, WordPress, mail), or filters that need careful regex so you do not ban healthy traffic.
Optional hardening checklist after the three fixes
Once lockouts, UFW ports, and jails behave:
- Confirm UFW default deny incoming and only required allows.
- Keep Fail2ban
ignoreipcurrent when office IPs change. - Watch
/var/log/fail2ban.logweekly or ship it to your monitoring. - Prefer key-only SSH; consider a non-default SSH port only as defence-in-depth after UFW/Fail2ban are correct—not instead of them.
- Document break-glass console steps so the next lockout is minutes, not hours.
sudo ufw status verbose
sudo fail2ban-client status
sudo grep -E "Ban|Unban" /var/log/fail2ban.log | tailWhen DIY is enough vs when to book Fixwebnode
DIY is enough when you still have console or SSH access, your stack is stock Ubuntu OpenSSH plus a simple web stack, and the three issues above match your symptoms. Follow the numbered steps, verify with ufw status and fail2ban-client status, and keep a second admin path.
Book Fixwebnode when you cannot reach the host at all, rules interact with load balancers or private networks, jails must cover multiple services, or a production site cannot tolerate trial-and-error. Fixwebnode is a direct specialist for remote Ubuntu hardening and recovery—not a place to post projects or collect bids. Start from the server support landing page and describe your Ubuntu version, whether UFW is enabled, and any Fail2ban lockout messages.
Talk through your Ubuntu hardening plan
If your Southbank or Melbourne VPS still shows repeated SSH noise, silent jails, or a firewall that blocked the wrong ports, bring your ufw status verbose and fail2ban-client status output to a short remote session. Fixwebnode can review ignoreip, jail.local, and allow rules with you, restore access safely, and leave a maintainable baseline.
Ready when you are: book a conversation via Fixwebnode server support. Have your provider console handy if SSH is already blocked—we will work from the symptoms you see, not a generic script.