Configuring a firewall for your Linux distribution
Confirm the current SSH port first. Apply rules from an existing session and test another connection before disconnecting.
Ubuntu or Debian with UFW
ufw allow PORT/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
ufw status verbose
AlmaLinux with firewalld
firewall-cmd --permanent --add-port=PORT/tcp
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
firewall-cmd --list-all
Alpine Linux
Alpine commonly uses nftables rather than UFW or firewalld. Install and configure its nftables service, permit established traffic, loopback, the displayed SSH port, and only the application ports you need. Validate with nft -c -f /etc/nftables.nft before loading the rules, then inspect them with nft list ruleset.
Replace PORT with the service page’s SSH port. Do not run multiple firewall managers without a deliberate design, and remember that an application must also listen on the permitted port.