linux下iptables防火墙的启动、停止以及打开或者关闭某个端口

CentOS 配置防火墙操作:

  查询防火墙状态:

[root@localhost ~]# service   iptables status

  停止防火墙:      

 [root@localhost ~]# service   iptables stop

  启动防火墙:       

[root@localhost ~]# service   iptables start

  重启防火墙:  

[root@localhost ~]# service   iptables restart

如何打开某个端口呢:

  1. 进入防火墙配置文件: 

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

  2.例如要打开3306端口:

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

  3.重启防火墙:

service  iptables restart

完整的配置文件如下:

# 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

如果想要关闭某个端口:在配置文件中去掉配置,重启防火墙就好了

posted @ 2019-08-21 17:27  车到山前必有路~  阅读(3725)  评论(0编辑  收藏  举报