No active firewall
- Check
net.firewall- Severity
- medium
- Runs
- on the server, in the daily run of the agent
- Looks at
- An nftables or iptables input chain that drops or rejects; ufw or firewalld when the rules cannot be read
What the check looks at
Whether the loaded nftables or iptables rules filter incoming traffic: an input chain with the policy drop, or
with drop or reject rules. Docker rules for container traffic and the ban chains of fail2ban and CrowdSec do not
count. When the agent cannot read the rules, an enabled ufw or a running firewalld passes; an enabled ufw whose
rules are not loaded fails.
Risk
Without a firewall, every service on a public address is reachable from the internet: next to SSH and the web server, a database installed for a test, a metrics exporter, an admin panel. A default-deny firewall keeps those closed, also when an update changes their configuration. The check net.public_listeners lists what listens.
How to fix it
Allow SSH before you turn on a default-deny policy, keep your SSH session open, and know how to reach the console of the server.
Ubuntu and Debian (ufw)
sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp # only if the server runs a web server
sudo ufw enable
RHEL, Rocky Linux and AlmaLinux (firewalld)
sudo dnf install firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
The default zone public allows ssh, dhcpv6-client and cockpit.
Alpine (nftables)
The shipped /etc/nftables.nft drops incoming traffic and does not allow SSH. Add your ports in a file in
/etc/nftables.d/ first:
apk add nftables
cat > /etc/nftables.d/50-services.nft <<'EOF'
table inet filter {
chain input {
tcp dport 22 accept comment "SSH"
}
}
EOF
nft -c -f /etc/nftables.nft
rc-update add nftables
rc-service nftables start
On a Docker host, ports that Docker publishes pass these rules, because Docker adds its own. Publish them on
127.0.0.1 or filter them in the DOCKER-USER chain; see Docker bypasses ufw.
How to check the fix
sudo ufw status verbose # ufw
sudo firewall-cmd --list-all # firewalld
sudo nft list ruleset # nftables
From another machine, nc -vz <server-ip> <port> must connect for the open ports and time out for the rest.
When a warning is fine
When a firewall of the provider (security groups, a cloud firewall) allows only the ports you need, and nobody can reach the server from inside the same network. A host firewall still helps: provider rules are easy to change by mistake and do not cover traffic from other servers in the same private network.