Firewalld is a host firewall for Linux that manages rules by zone and lets you change them without restarting anything. You install it with your distro’s package manager, enable the service, and manage it with firewall-cmd. On RHEL, Rocky Linux, AlmaLinux and Fedora it is usually installed and running already. On Ubuntu and Debian it is in the standard repositories, but Ubuntu ships with ufw instead, and you should only run one of them.
Before you start on a remote server: the default zone allows SSH, but check it straight after enabling firewalld (below), while your current session is still open.
Install Firewalld
RHEL, Rocky Linux, AlmaLinux and Fedora
sudo dnf install -y firewalld sudo systemctl enable --now firewalld
Ubuntu and Debian
# Ubuntu: turn off ufw first so the two do not fight over the rules sudo ufw disable sudo apt update sudo apt install -y firewalld sudo systemctl enable --now firewalld
Amazon Linux
I first wrote this post in 2020 on an Amazon Linux 2 EC2 instance, where it was sudo yum install -y firewalld followed by the same systemctl enable --now firewalld:


Amazon Linux 2 reached the end of its support in June 2026 (AWS FAQ). On EC2, security groups usually do this job outside the instance, so a host firewall is an extra layer rather than the main one. On Amazon Linux 2023, run dnf info firewalld first to see whether the package is available in your repositories.
Check It Is Running
# "running" means the firewall is active sudo firewall-cmd --state # the zone your network interface is in, and everything it allows sudo firewall-cmd --get-active-zones sudo firewall-cmd --list-all
In the --list-all output, services: should include ssh. If it does not and you are connected remotely, add it now (next section) before you log out.
Open and Close a Port
Rules added with --permanent survive a reboot but only take effect after a reload. Rules without it apply at once and are lost on reload, which is handy for testing. This example opens TCP 1433, the default port for SQL Server on Linux:
# Change 1433/tcp to the port and protocol you need sudo firewall-cmd --permanent --add-port=1433/tcp sudo firewall-cmd --reload # Confirm it is listed sudo firewall-cmd --list-ports # Close it again sudo firewall-cmd --permanent --remove-port=1433/tcp sudo firewall-cmd --reload
For well-known services you can use the service name instead of the port, for example --add-service=ssh or --add-service=https. firewall-cmd --get-services lists the names it knows. Which ports SQL Server needs is covered on sqldba.blog in SQL Server Ports: 1433, Dynamic Ports and Firewall Rules.
The full reference is the firewalld documentation. On Windows the same job is a firewall rule created with New-NetFirewallRule.
Related
If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.
Leave a Reply