Skip to content
VeloxMedia
VPS guide

Manage firewalld on AlmaLinux, Rocky Linux and Fedora

RHEL-family distributions ship firewalld enabled. It uses zones and named services rather than raw rules, which feels unfamiliar at first and becomes very tidy once the model clicks.

Beginner · About 3 min read · Updated 27 October 2026

Check that it is running

sudo systemctl status firewalld
sudo firewall-cmd --state
sudo firewall-cmd --get-active-zones

On a fresh VPS the network interface normally sits in the public zone, which allows SSH and DHCPv6 client traffic and blocks everything else inbound.

Runtime versus permanent

Every firewalld change is either runtime (active now, lost on reload or reboot) or permanent (saved, applied on next reload). The safe workflow is to test at runtime and then save:

sudo firewall-cmd --add-service=http
# test that the site loads
sudo firewall-cmd --runtime-to-permanent

Or make the change permanent and reload in one go:

sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Open services and ports

Named services bundle the right ports and protocols:

sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --permanent --add-port=51820/udp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

firewall-cmd --get-services lists every predefined service, including postgresql, mysql, wireguard and cockpit.

Restrict a service to one address

Rich rules handle source-based access. To let only an office IP reach PostgreSQL:

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="198.51.100.7" service name="postgresql" accept'
sudo firewall-cmd --reload

For several trusted addresses, a cleaner pattern is a dedicated zone bound to source addresses:

sudo firewall-cmd --permanent --new-zone=office
sudo firewall-cmd --permanent --zone=office --add-source=198.51.100.0/28
sudo firewall-cmd --permanent --zone=office --add-service={ssh,postgresql}
sudo firewall-cmd --reload

Traffic from those addresses now uses the office zone; everyone else falls through to public.

Close what you do not need

Many RHEL-family images allow cockpit (port 9090) in the public zone. If you do not use the web console, remove it:

sudo firewall-cmd --permanent --remove-service=cockpit
sudo firewall-cmd --reload

Moving SSH to another port

SELinux must be told about the new port as well as the firewall:

sudo semanage port -a -t ssh_port_t -p tcp 2222
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload

Only then change Port in the SSH configuration and reload sshd. Keep your current session open until a new login on the new port succeeds.

Logging dropped packets

sudo firewall-cmd --set-log-denied=unicast
sudo journalctl -k -f | grep -i reject

Set it back with --set-log-denied=off when you are done.

If you get locked out

Use the browser-based VNC console in the VeloxMedia control panel and run sudo firewall-cmd --reload to discard runtime mistakes, or sudo systemctl stop firewalld while you fix permanent rules. Firewall rules in the control panel can be used alongside firewalld for a second layer of protection.

Common questions

What is the difference between runtime and permanent rules in firewalld?

Runtime rules apply immediately but disappear on reload or reboot. Permanent rules are saved and take effect after a reload. Test changes at runtime, then save them with firewall-cmd --runtime-to-permanent.

How do I open a port in firewalld?

Run firewall-cmd --permanent --add-port=PORT/tcp (or /udp), then firewall-cmd --reload. For common software, use --add-service with a named service such as http, https or postgresql.

How do I allow only one IP address to a port?

Use a rich rule with a source address and a service or port, or create a dedicated zone, add the trusted addresses as sources and allow the service in that zone.

Why does SSH fail after I change its port on Rocky Linux?

SELinux only allows SSH on approved ports. Add the new port with semanage port -a -t ssh_port_t -p tcp PORT, open it in firewalld, and then reload sshd.

Deploy your first server in under a minute

Pick a region, choose a size and connect over SSH. No setup fees, cancel anytime.