Rocky Linux

How to Enable/Disable the Firewall on Rocky Linux 9

A firewall is an essential service for server and system security. A predetermined set of rules controls and filters the network traffic passing to Linux servers. A firewall blocks all external traffic except if they have any suspicious issues.

Firewalld is a lightweight and popular command-line management solution for Linux servers. It manages the network traffic using the concept of zones. You can assign the network interfaces to zones using the predefined rules. You can configure the firewall to block and allow the services or ports associated with the application.

Permanently or temporarily enabling or disabling the firewalld is one of the essential related tasks to troubleshoot the server access. This guide sees how to enable/disable the firewall on Rocky Linux 9.

How to Enable/Disable the Firewall on Rocky Linux 9

RHEL-based distros like Fedora, Rocky Linux, CentOS, and AlmaLinux have an installed firewalld by default. First, use the following command to check the firewalld’s status:

sudo systemctl status firewalld

You can also use any of the following commands to check the status of the firewalld:

sudo firewall-cmd --state
sudo systemctl is-active firewalld
sudo systemctl is-active firewalld.service
sudo systemctl status firewalld.service

Disable the Firewall on Rocky Linux 9

You can stop the firewalld service on the Rocky Linux server using any of the following commands:

sudo systemctl stop firewalld.service
sudo service firewalld stop
sudo systemctl stop firewalld

After stopping the firewalld service, you will see that its services become inactive in the status information:

Once you disable the firewall, you must manually enable or restart the system.

In some cases, the security groups manage the firewall. In this situation, a firewall is not required on a host. Hence, you can permanently disable the firewalld service through the following command:

sudo systemctl disable firewalld

If you don’t want to go for multiple steps to stop and disable the firewalld service, you can also use a single command only:

systemctl disable firewalld --now

The previous command uses the –now argument with the systemctl disable command to apply the changes to the runtime environment.

To prevent the firewalld services from the firewalld-bus interface or any other service from running, you can mask its services with the following command:

sudo systemctl mask firewalld

Now, your Firewall Daemon service is masked; you cannot enable it unless its services are unmasked. Masking the firewalld services means that no other service or process has the privilege to enable your firewall. Let’s check the status of the firewall:

sudo systemctl is-active firewalld

Enable the Firewall on Rocky Linux 9

Since we masked the firewalld service in the previous method, it will no longer start automatically after restarting the system. Now, unmask the service first through the following command:

sudo systemctl unmask firewalld

After unmasking the service, start the firewalld service using any of the following commands:

sudo service firewalld start
sudo systemctl start firewalld

If you want to check the status of the currently running firewall service, run the following command:

sudo systemctl start firewalld

You can enable the firewall service permanently through the following command:

sudo systemctl enable firewalld

Similarly, you can run the single command to enable the firewalld service:

sudo systemctl enable firewalld --now

Skip the systemctl start firewall step. You can enable it by starting the firewalld service as soon as possible with the –now flag.

Finally, you can check the status to see that the firewalld service is enabled.

sudo systemctl status firewalld

Conclusion

This is all about enabling and disabling the firewalld on Rocky Linux 9. The firewall protects your machine and system from unwanted external traffic. It enables you to define the rules to control and protect the incoming network traffic. You can block, deny, or allow the traffic by disabling the firewall in your system.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.