How to check whether the firewall is turned on in Linux: First use the "ifconfig" or "ip addr" command to check the IP of the Linux host; then use the "service iptables status" command to check whether the firewall is turned on.
![Check if the firewall is turned on in linux](https://img.php.cn/upload/article/202101/25/2021012515514823486.jpg)
Demo environment in the article: centos6 system, Dell G3 computer.
Recommendation: "linux video tutorial"
linux check whether the firewall is turned on and delete iptables rules
Preparation
First confirm the IP
For the test later, we first confirm the IP of the linux host. You can use ifconfig or ip addr to view.
![1611561229542604.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/125/739/522/1611561229542604.png)
Check the open ports that the system is listening to and confirm with netstat. As we see port 143 is open.
![1611561240225269.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/793/616/573/1611561240225269.png)
How to check whether the firewall is turned on or not? Centos6 uses service iptables status to check
![1611561244334586.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/432/175/787/1611561244334586.png)
##centos7 system iptables is called firewalld. Use systemctl status firewalld to check whether it is started. As shown in the figure, it is already running
![1611561249292151.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/160/132/892/1611561249292151.png)
Restart the firewall service. Since the current release version centos7 is the mainstream, the following part will introduce the usage of the firewall of centos7. Restarting and closing the firewall service will not prompt you. Unless there is an error configuration.
![1611561253101084.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/506/700/692/1611561253101084.png)
View iptables rules If you want to view the rules currently running by iptables, use iptables -L to list them.
![1611561257683450.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/291/414/352/1611561257683450.png)
As shown in this column, my Linux host port 143 firewall is open to the outside world.
![1611561269304478.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/529/579/351/1611561269304478.png)
Test whether the firewall is OK through a computer on the same network segment. Telnet linux host IP 143
![1611561275451190.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/566/518/525/1611561275451190.png)
Delete iptables Rules If you delete the iptables rules, you can test and see that port 143 is unavailable. The command is
firewall-cmd --zone= public --remove-port=143/tcp --permanent
![1611561280960959.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/590/966/826/1611561280960959.png)
View the port number input allowed by the firewall The command firewall-cmd --zone=public --list-ports can view the port numbers outside the firewall list of external network computers and delete them accordingly. If you want to cancel deletion of iptables rules, you can directly stop or disable the firewalld service.
![1611561284987311.png Check if the firewall is turned on in linux](https://img.php.cn/upload/image/938/853/653/1611561284987311.png)
The above is the detailed content of Check if the firewall is turned on in linux. For more information, please follow other related articles on the PHP Chinese website!