The CentOS system image is one of the images commonly used by our ECS. For server security management, firewall defense is mostly used, including port pass and rule defense processing, the so-called soft security processing. CentOS comes with a powerful firewall tool called iptables or firewalld. This article will introduce some common CentOS firewall management commands and operation cases, and show how to turn off the firewall.

1. View firewall status
To view the current firewall status
#CentOS 7 and above use firewalld sudo firewall-cmd --state #CentOS 6 and below use iptables sudo service iptables status
This will show whether the firewall is active.
2. Open port
If you need to allow specific ports to pass through the firewall, you can use the following command:
#CentOS 7 and above use firewalld sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent sudo firewall-cmd --reload #CentOS 6 and below use iptables sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT sudo service iptables save sudo service iptables restart
The above command will open port 8080 and allow TCP traffic to pass through.
3. Close port
If you need to close an open port, you can use the following command:
#CentOS 7 and above use firewalld sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent sudo firewall-cmd --reload #CentOS 6 and below use iptables sudo iptables -D INPUT -p tcp --dport 8080 -j ACCEPT sudo service iptables save sudo service iptables restart
This will remove port 8080 from the firewall rule.
4. Turn off firewall
If you want to completely shut down the firewall, you can use the following command:
#CentOS 7 and above use firewalld sudo systemctl stop firewalld sudo systemctl disable firewalld #CentOS 6 and below use iptables sudo service iptables stop sudo chkconfig iptables off
This will stop the firewall service and disable its automatic start.
To sum up, here are some common CentOS firewall management commands and operation cases, including viewing firewall status, opening ports, closing ports, and closing firewalls. By familiarizing yourself with these commands, you can better manage and configure the CentOS firewall to improve the security of the server.