Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Fix firewall-cmd command not found Error in RHEL/CentOS 7?
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 encounter 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.
Understanding 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:
Missing or incomplete installation of the Firewalld package
Incorrect system path variables
Outdated system packages
Disabled or inactive FirewallD service
How to Identify the Error
To identify if you are experiencing this error on your RHEL/CentOS 7 server, run these diagnostic commands:
$ sudo systemctl status firewalld.service $ which firewall-cmd $ whereis firewalld
If you see messages indicating that either the FirewallD service or firewall-cmd package is missing or inactive, then you are experiencing this issue. Additionally, check if the necessary directories are included in your PATH:
$ echo $PATH
Method 1: Installing FirewallD Package
If the error is due to the absence of the Firewalld package, install it using the YUM package manager:
$ sudo yum update -y $ sudo yum install firewalld -y
After installation, start and enable the FirewallD service:
$ sudo systemctl start firewalld $ sudo systemctl enable firewalld
Verification
Verify the installation by checking the service status:
$ systemctl status firewalld
If the output shows Active (running) status, the installation was successful.
Method 2: Checking System Path Variables
If FirewallD is installed but the command is still not found, the issue might be with system path variables. The firewall-cmd executable is typically located in /usr/bin/ or /usr/sbin/.
Check your current PATH:
$ echo $PATH
If /usr/sbin/ is missing, add it temporarily:
$ export PATH=$PATH:/usr/sbin/
To make this change permanent, edit your .bashrc file:
$ nano ~/.bashrc
Add this line at the end:
export PATH=$PATH:/usr/sbin/
Save the file and reload it:
$ source ~/.bashrc
Method 3: Reinstalling FirewallD Package
If the above methods fail, try reinstalling the FirewallD package completely:
$ sudo yum remove firewalld -y $ sudo yum install firewalld -y $ sudo systemctl start firewalld $ sudo systemctl enable firewalld
Verification After Reinstallation
Test the firewall-cmd command:
$ firewall-cmd --version $ systemctl status firewalld
Additional Configuration
Updating System Packages
Keep your system packages updated to prevent compatibility issues:
$ sudo yum update -y
Enabling FirewallD at Boot
Ensure FirewallD starts automatically at boot time:
$ sudo systemctl enable firewalld.service
Verify the service is enabled:
$ sudo systemctl is-enabled firewalld.service
The output should show enabled.
Common Troubleshooting Steps
| Issue | Solution | Command |
|---|---|---|
| Service not running | Start the service | sudo systemctl start firewalld |
| Service disabled | Enable at boot | sudo systemctl enable firewalld |
| Package not installed | Install package | sudo yum install firewalld -y |
| PATH issue | Add to PATH | export PATH=$PATH:/usr/sbin/ |
Conclusion
The firewall-cmd command not found error is typically caused by missing FirewallD packages, incorrect PATH variables, or inactive services. By following the methods outlined above installing/reinstalling the package, checking PATH variables, and ensuring the service is enabled you can resolve this error effectively. Regular system updates and proper service configuration help prevent such issues from recurring.
