It is necessary to configure the iptables firewall in CentOS. Let's learn how to configure it!
Set the firewall in Linux. Take CentOS as an example to open the iptables configuration file:
Vi/etc/sysconfig/iptables
Run the/etc/init. d/iptables status Command to check whether port 80 is enabled. If port 80 is not enabled, you can use either of the following methods:
1. Modify the vi/etc/sysconfig/iptables command to add the firewall to open port 80
-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
2. Disable/enable/restart the Firewall
/Etc/init. d/iptables stop # start enabled # restart
3. permanently disable the Firewall
Chkconfig -- level 35 iptables off/etc/init. d/iptables stop iptables-P INPUT DROP
4. enable port 21 in Active Mode
Iptables-a input-p tcp -- dport 21-j ACCEPT
5. Enable passive mode 49152 ~ Port 65534
Iptables-a input-p tcp -- dport 49152: 65534-j ACCEPT iptables-a input-I lo-j ACCEPT iptables-A INPUT-m state -- state ESTABLISHED-j ACCEPT
Note:
Be sure to leave a path for yourself and leave a VNC Management port and an SSh Management port.
You must modify the file based on your server.
After all the modifications, restart iptables:
Service iptables restart
You can verify whether all rules have taken effect:
Iptables-L
Through the introduction of this article, we have clearly understood the process of configuring iptables firewall in CentOS. I hope everyone can master it!