Cent OS firewall configuration port open

CentOS 6 built-in firewall is iptables, Cent OS7, built-in firewall is firewalld

iptables firewall settings

1. Open / close / restart firewall

开启防火墙(重启后永久生效):chkconfig iptables on
 
关闭防火墙(重启后永久生效):chkconfig iptables off
 
开启防火墙(即时生效,重启后失效):service iptables start
 
关闭防火墙(即时生效,重启后失效):service iptables stop
 
重启防火墙:service iptables restartd

2. Check the firewall to open the ports
here to open port 8080 as an example:

(1) open port

iptables -A INPUT -p tcp --dport 1024 -j ACCEPT

(2) to save and take effect

/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart

4. Open the specified range of port

For example all open ports between 1024-10240:

iptables -A INPUT -p tcp --dport 1024:10240 -j ACCEPT

firewalld firewall settings

1. Check the firewall status

systemctl status firewalld

Here If prompted firewalld.service could not be found. It indicates that your system does not install a firewall, you do not need to set.

2. Open the specified port

Here to open port 1024 as an example:

firewall-cmd --zone=public --add-port=1024/tcp --permanent

-permanent parameter indicates permanent, this argument does not restart after failure.

3. Restart the firewall

firewall-cmd --reload # restart firewall
systemctl firewalld.service STOP # Stop firewall
systemctl disable firewalld.service # prohibit firewall boot

firewall-cmd --reload # restart firewall
systemctl firewalld.service STOP # Stop firewall
systemctl disable firewalld.service # prohibit firewall startup
firewall-cmd --state # view the default firewall status (turn off the display after notrunning, after opening display running)
1
firewall-cmd --state # view the default firewall status (closed after displaying notrunning, display running after opening)

Guess you like

Origin www.cnblogs.com/zhangqiuchi/p/10991619.html