For CentOS 7 users, security is one of the most important aspects of system management. Therefore, effective firewall management is the key to minimizing potential threats to your systems. In this guide, we will cover many topics ranging from activating the FirewallD service to creating custom rules. If you're ready, let's explore what you can do to make your system more secure.
FirewallD is the default dynamic security firewall management tool that comes with CentOS 7. This tool offers a flexible and easy method for managing network connections and traffic. The first step is to check whether the FirewallD service is running on your system.
sudo systemctl status firewalld
If the service is not running, you can activate it with the following command:
sudo systemctl start firewalld
Additionally, to ensure that FirewallD starts automatically when the system reboots, use the following command:
sudo systemctl enable firewalld
After confirming that FirewallD is running, you can begin with basic configurations.
FirewallD uses the concepts of zones and services to manage network traffic. Zones are used to apply rules specific to certain network environments, and each zone can have different security levels. For example, the "public" zone generally has more restrictive rules.
To see which services are open in a zone, use the following command:
sudo firewall-cmd --zone=public --list-services
To add a specific service to a zone, use the following command:
sudo firewall-cmd --zone=public --add-service=http --permanent
To apply the changes, reload the firewall:
sudo firewall-cmd --reload
For more control over network traffic, you can create custom port rules. For example, to open a specific port:
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
Similarly, to remove a port:
sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent
After either action, don't forget to reload the firewall to apply the changes:
FirewallD also provides various options for monitoring and logging network traffic. To monitor network traffic, you can check the system log files. To increase the logging level for more detail:
sudo firewall-cmd --set-log-denied=all
This setting will log all denied connection attempts. Logs are typically stored in the /var/log/firewalld directory. Reviewing these logs can help you quickly take action in case of a potential security breach.
/var/log/firewalld
If you're encountering issues with FirewallD, reviewing the log files is usually the first step. Common errors and warnings in the logs can help you identify the source of the problem. For example, a denied connection attempt might look like this:
sudo cat /var/log/firewalld | grep "DENIED"
Additionally, there are commands available to reset and reconfigure firewall rules. To reset all rules:
sudo firewall-cmd --complete-reload
This command will remove all temporary rules and reload the permanent ones.
FirewallD is a dynamic firewall management tool for CentOS 7. It allows you to manage network traffic in a simple and flexible way.
You can check the service status using the command sudo systemctl status firewalld.
Log files are usually stored in the /var/log/firewalld directory.
To open a custom port, use the command sudo firewall-cmd --zone=public --add-port=[port]/tcp --permanent.
sudo firewall-cmd --zone=public --add-port=[port]/tcp --permanent
To apply changes, reload the firewall with sudo firewall-cmd --reload.