Centos7 system firewall usage tutorial [detailed explanation]

CentOS 7 is a common Linux operating system. As the first line of defense for network security, the firewall is crucial to server security. This article will introduce the usage tutorial of the firewall in the CentOS 7 system, including how to enable, disable, configure, and add and delete firewall rules.

1. Check the status of the firewall
Before starting the operation, you need to confirm the status of the firewall, you can use the following command to check:

systemctl status firewalld
1.
If "active (running)" is displayed, it means that the firewall is running, and if "inactive (dead)" is displayed, it means that the firewall is closed.

2. Turn on the firewall
If the firewall is turned off, you can use the following command to turn on the firewall:

systemctl start firewalld
1.
3. Turn off the firewall
If you need to turn off the firewall, you can use the following command:

systemctl stop firewalld
1.
4. Firewall configuration
1. View firewall rules
Use the following command to view the current firewall rules:

firewall-cmd --list-all
1.
2. Add a firewall rule
To add a firewall rule, you need to know the type of the added rule, such as port, service, etc. The following is an example command to add a port rule:

firewall-cmd --znotallow=public --add-port=80/tcp --permanent
1.
--znotallow=public: Specify the firewall zone as "public".
--add-port=80/tcp: Add TCP port 80 rule.
--permanent: Save the rule to the firewall permanent configuration.
3. Delete a firewall rule
To delete a firewall rule, you need to specify the type and content of the rule to be deleted. The following is an example of the command to delete a port rule:

firewall-cmd --znotallow=public --remove-port=80/tcp --permanent
1.
--znotallow=public: Specify the firewall zone as "public".
--remove-port=80/tcp: Remove TCP port 80 rule.
--permanent: Remove the rule from the firewall permanent configuration.
V. Summary
This article introduces the usage tutorial of the firewall in the CentOS 7 system, including operations such as opening, closing, and configuring firewall rules. When using a firewall, you need to add and delete rules according to actual needs to improve server security.
-----------------------------------
 

Guess you like

Origin blog.csdn.net/fzy18757569631/article/details/130583360