Under linux iptables firewall start, stop, and turn on or turn off a port

CentOS configured firewall actions:

  Firewall status query:

[root@localhost ~]# service   iptables status

  Stop Firewall:      

 [root@localhost ~]# service   iptables stop

  Start Firewall:       

[root@localhost ~]# service   iptables start

  Restart the firewall:  

[root@localhost ~]# service   iptables restart

How to open a port it:

  1. Go to the firewall configuration file: 

[root@localhost ~]# vi /etc/sysconfig/iptables

  2. For example, to open port 3306:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

  3. Restart Firewall:

service  iptables restart

Full configuration file as follows:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

If you want to close a port: Remove the configuration in the configuration file, reboot the firewall just fine

Guess you like

Origin www.cnblogs.com/huashuohehe/p/11390016.html