firewall on and off (effective immediately, fail after reboot):
$ sudo service iptables start #开启 $ sudo service iptables stop #关闭
firewall on and off (takes effect after reboot):
$ sudo chkconfig iptables on$ sudo chkconfig iptables off
To open the relevant port :
Modify the/etc/sysconfig/iptables file to add the following:
-A input-p tcp-m state--state new-m TCP--dport 22-j ACCEPT
After modifying the iptables, restart the firewall to take effect:
$ sudo service iptables restart
-A: Add a rule to the rule chain input
INPUT: Rule Chain
-P: Represents the Packet usage protocol followed by TCP, which indicates the use of the TCP protocol
-M: Indicates an explicit match extension followed by state, indicating that the state module is explicitly loaded and used. New represents the state value of the status. The next-m TCP--dport 22 means explicitly loading the TCP module and specifying a matching condition of 22 for the target port.
-j ACCEPT: Specifies the target (action), which means to continue processing the grouping.
to view UDP-type ports :
$ NETSTAT-NUPL #UDP类型的端口
to view a port of type TCP :
$ NETSTAT-NTPL #TCP类型的端口
Use the lsof command to see if a port is open :
$ lsof-i:80
Take Port 80 as an example, if a display description is already open, it will not open if no instructions are displayed.
Linux Open firewall port and view, turn on related port number