Security
Firewall and bans
The nftables firewall that rolls back by itself unless you confirm, fail2ban protection for every public service, your own jails with a dry run, geoblocking, and administrative SSH that is reachable only over a VPN.
On this page
Berth protects the network edge of a server in three ways: a firewall that decides which services are reachable at all, fail2ban that blocks addresses after repeated abuse, and a fixed rule that administrative SSH never faces the open internet. This article explains each, and how to change them without locking yourself out.
The firewall
The firewall is built on nftables and managed under Security → Firewall. It is on for every new installation. It allows in only the services you choose. Traffic over the VPN, traffic from the server itself and replies to outbound connections are always allowed.
On the page you can:
- choose which services are open from outside under Services that are open, and limit a service to specific addresses;
- open extra ports under Extra ports;
- block addresses or ranges under Blocked addresses;
- see the resulting rule set under Rules.
The System → Ports page, or berth security listeners, shows every listening port with its process and what the firewall does with it. Use it to spot a service listening where it should not.
Confirm or roll back
A firewall change can lock you out of your own server. Berth therefore never applies one without a way back:
- Make the change and click Apply.
- In a new browser tab, check that the panel, the websites and mail still work.
- Click Confirm.
Without a confirmation within the window, the previous rules come back by themselves. Roll back now does that immediately. On the server:
berth security firewall # show the current state and config
berth security firewall --apply rules.json --rollback 120 # apply with a 120-second window
berth security firewall --confirm # keep the new rules
berth security firewall --rollback-now # go back immediatelyThe window is between 10 and 900 seconds. When four-eyes approvals are on, a firewall change needs a second administrator. See Audit trail and approvals.
On an existing server that has no firewall yet, berth install --firewall turns it on with a confirmation window, so you can confirm in the panel or with --confirm.
Administrative SSH only over a VPN
As a product rule, administrative SSH on port 22 is reachable only over a VPN interface (WireGuard or Tailscale, for example), independent of the firewall settings. Brute-force attacks on the root account from the internet simply never reach sshd. This is why a VPN interface is one of the system requirements.
Customers use a separate SSH port for SFTP, and for shell access when their package allows it. The panel shows that port on the customer's SSH and FTP pages. See Files, FTP and SSH.
If the panel itself is unreachable, Rescue mode gives you a way in over the VPN.
Administrator accounts with expiring keys
System → Admin access manages the people who may log in to the server itself over that VPN. Each administrator gets their own account in the berth-admins group, with SSH keys that must carry an expiry date; an expired key is removed automatically. Sudo is granted (or taken away) through a drop-in file that is checked with visudo -c before it is used. Granting access in the panel is a request that you confirm with your passkey in the admin terminal, or as root on the command line:
berth admins add jane --key-file jane.pub --expires 2027-03-31 # with sudo, unless --no-sudo
berth admins key-add jane --key-file laptop.pub --expires 2027-03-31
berth admins sudo jane offBerth can also manage sshd on port 22 for you: keys only, and only for the berth-admins group. berth sshd apply tests the new configuration with sshd -t first and refuses while no administrator has a valid key. The change rolls back on its own unless you confirm with berth sshd confirm that you can still get in.
fail2ban: blocking repeated abuse
fail2ban watches the logs of every public service and temporarily blocks an address that keeps failing. Berth configures jails for:
- SSH and SFTP;
- the panel sign-in;
- Postfix (SMTP and submission) and Dovecot (IMAP and POP3);
- webmail;
- FTP;
- nginx request limits;
- scanners probing for well-known vulnerable paths;
- repeat offenders (recidive), who are blocked for longer and on all ports.
A block covers both TCP and UDP, including HTTP/3. Repeat offenders get progressively longer bans.
Security shows per jail which addresses are blocked under Blocked addresses, lets you unblock or block an address yourself, and shows the repeat offenders under Repeat offenders.
berth security bans # blocked and trusted addresses per jail
berth security ban --ip 203.0.113.50 # block (in the panel jail by default)
berth security unban --ip 203.0.113.50 # unblock in every jail
berth security jails # ban time, window, attempts, enabled jails
berth security recidive # repeat-offender settingsYou can adjust the ban time, the window in which attempts count, the number of attempts and which jails are on, with berth security jails --ban-time … --find-time … --max-retry … --disable …, or on the same page.
Trusted addresses
Addresses on the trusted list are never blocked. The server's own addresses are always on it, so a site that calls itself cannot get the server banned. Add your office or VPN range so a mistyped password does not lock out the whole team:
berth security trusted --set 192.0.2.0/24,2001:db8:10::/48The panel also offers to trust the address you are using right now (Trust your own address?).
Attack-wave alerts
A single ban does not send a notification. Hosting servers are attacked all day and individual bans are noise. Berth does alert when there is a wave of bans, or a wave of refused web requests across the server. The alert names the busiest jails or sites. You can adjust or silence these rules like any other alert, see Notifications and alerts.
Your own jails, with a dry run
Run something Berth does not know about, such as Gitea, a game server or your own API? Add your own jail under Security → Custom monitoring:
- Choose the source: a log file under
/var/logor a domain's log directory, or a systemd unit (read from the journal). - Choose one of fail2ban's standard filters, or write your own
failregexwith<HOST>where the address appears. - Click Dry run. Berth runs the filter over the latest lines of the source and shows which lines match and which addresses would be blocked. Nothing changes yet.
- When the result is right, save. Berth checks the configuration with
fail2ban-client -tbefore it reloads fail2ban, so a broken jail never stops the existing ones.
On the server:
berth security jail filters # fail2ban's standard filters
berth security jail test --unit gitea.service \
--failregex 'Failed authentication attempt for .* from <HOST>'
berth security jail add --name gitea --label "Gitea sign-in" --unit gitea.service \
--failregex 'Failed authentication attempt for .* from <HOST>'
berth security jail list
berth security jail remove --name giteaGeoblocking
Country data comes from a local copy of the DB-IP Lite database, so no visitor address is sent to a lookup service.
- Per site: keep out visitors from some countries, or allow only some, under Geoblocking on the domain page, or with
berth domain geo --domain example.nl --block <countries>or--allow NL,BE. - The panel itself: limit the panel, the API and webmail to certain countries with
berth geoip panel. The panel refuses a setting that would block the address you are using. Status pages stay reachable.
If you lock yourself out of the panel anyway, turn it off on the server with berth geoip panel --off.
Outbound traffic
The firewall controls what comes in. What customer sites may send out is controlled per subscription, see Isolation.