How to Fix firewall-cmd command not found Error in RHEL/CentOS 7?


Introduction

Firewall-cmd is a powerful command-line utility that allows you to configure the firewall on Red Hat Enterprise Linux (RHEL) and CentOS 7. It is used to manage the FirewallD daemon, which is responsible for managing the iptables firewall rules.

However, some users have reported encountering an error message "firewall-cmd: command not found" when trying to issue commands related to FirewallD. This error can be frustrating for users who rely on FirewallD as it makes it impossible to modify firewall rules using Firewall-cmd.

The cause of this error is usually due to a missing or corrupt installation of the Firewalld package or an issue with system path variables. Fortunately, there are several ways you can resolve this error and get back to managing your firewall efficiently using Firewall-cmd.

Understanding the Error

Explanation of what causes the error

The firewall-cmd command not found error occurs in RHEL/CentOS 7 when the system is unable to locate the firewall-cmd command. This can happen due to several reasons, such as missing or incomplete installation of Firewalld package, incorrect system path variables, or outdated system packages. Firewalld is a service daemon that provides a dynamically managed firewall with support for network/firewall zones to configure a variety of internet connections.

When this service is not installed correctly, it can cause problems with system security and network access. Firewall-cmd is an essential tool to manage and modify firewalls in RHEL/CentOS 7 environments.

Users typically encounter this error when they are trying to run the firewall-cmd command from their terminal but receive an error message stating that the command was not found. This error often leads users to believe that the FirewallD service may be down or malfunctioning in some way but often indicates a simple problem related to settings or installation issues.

How to identify if the error is present on your system

To identify if you are experiencing a firewall-cmd command not found error on your RHEL/CentOS 7 server, try running the following commands in your terminal −

$ sudo systemctl status firewalld.service 
$ which firewall-cmd 
$ whereis firewalld

If you see any messages indicating that either FirewallD service or Firewall-CMD package is missing or inactive, then it confirms that you are experiencing this issue.

If both services appear active and running correctly, check if there's an outdated version of Firewalld installed on your system using yum info firewalld. Check if all necessary directories containing FirewallD executables are included in $PATH by typing echo $PATH.

Fixing the Error

Method 1: Installing FirewallD Package

If the firewall-cmd command not found error is due to the absence of Firewalld package, we can fix it by installing the package using Yum package manager. To begin with, we need to open our terminal and run Yum update command to ensure that all system packages are updated and up-to-date. Next, we need to run a command to install Firewalld package as shown below −

$ sudo yum install firewalld -y 

The above command will download and install Firewalld package along with its dependencies. Once installed successfully, reboot your system for the changes to take effect.

Verification steps to confirm successful installation −

After rebooting our system, we can verify whether Firewalld has been installed successfully or not by running a simple command in the terminal −

$ systemctl status firewalld 

If the output shows "Active (running)" status of firewalld service, then it means that the installation was successful.

Method 2: Checking System Path Variables

If Firewalld is already installed on your system but still you are encountering firewall-cmd command not found error then it might be due to incorrect or unavailable system path variables. In this case, we need to check our path variables settings and update them accordingly. Explanation of how system path variables can affect firewall-cmd command functionality −

Path variables in Linux systems define where executable files are located that can be executed from anywhere on our Linux machine without specifying their entire path location. Hence if they are not set correctly or missing some important paths like /usr/sbin/, you might face issues while executing commands like firewall-cmd.

Steps on how to check and update system path variables: To check if there is any issue with system path variables related to Firewalld, we need to run the following command in the terminal −

$ echo $PATH 

The above command will display the current PATH variable settings. If it does not include /usr/sbin/, then we need to add this path.

We can do this by editing the .bashrc file, which controls our user's terminal environment. To edit .bashrc file, we need to run the following command in the terminal −

$ nano ~/.bashrc 

In this file, go to the end of its contents and add a new line with "export PATH=$PATH:/usr/sbin/" and save it. Close and reopen your terminal.

Method 3: Reinstalling Firewalld Package

If both of the above methods fail to fix firewall-cmd command not found error then reinstalling Firewalld package might be our last resort. This method will ensure that all files related to Firewalld are re-installed.

Detailed guide on how to reinstall Firewalld package using Yum package manager: We can start with cleaning any leftover files related to firewalld using below command

$ sudo yum remove firewalld -y

Next step is installing firewalld again with yum install like before.

$ sudo yum install firewalld -y

Verification steps after successful re-installation:

After reinstalling firewalld through above steps, Verify if it installed properly. we can verify whether Firewalld has been installed successfully or not by running a simple command in the terminal −

$ systemctl status firewalld 

If you see "Active (running)" status of firewall-cmd service, then it means that re-installation was successful.

Additional Tips and Tricks

Updating System Packages

Keeping your system packages updated is essential in preventing firewall-cmd errors. Outdated software can cause compatibility issues with the FirewallD package, resulting in command not found errors when running the firewall-cmd tool.

To update your system packages, you can use the yum package manager. To update all packages on your system, simply enter the following command −

sudo yum update

This command will check for available updates for all installed packages and prompt you to install them. It's important to note that updating some packages may require a system restart.

Enabling FirewallD Service at Boot Time

Enabling the FirewallD service at boot time ensures that it starts up automatically every time you restart your system. This is important because if the service is not started, you'll receive firewall-cmd command not found errors since there won't be any active firewall services running.

To enable FirewallD service at boot time, follow these steps −

  • Open a terminal window.

  • Type in the following command and hit Enter −

sudo systemctl enable firewalld.service
  • If prompted, enter your root password.

  • The above command will enable Firewalld at startup.

  • You can verify whether Firewalld has been enabled successfully by running −

sudo systemctl is-enabled firewalld.service

If it returns "enabled", then Firewalld has been successfully configured to start on boot.

Conclusion

Fixing a firewall-cmd command not found error can be frustrating but with this guide, hopefully, you've found a solution that works for you. Always remember to update your system packages regularly, check your system path variables, and reinstall the FirewallD package if necessary.

Additionally, enabling the FirewallD service at boot time is crucial for preventing firewall-cmd command not found errors from cropping up in the future. By following these tips and tricks and staying vigilant with your system maintenance, you can avoid many common issues that arise when using Firewalld on RHEL/CentOS 7.

Updated on: 12-Jun-2023

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements