之所以称为CentOS6下操作防火墙,是因为CentOS7防火墙与之前版本不同,配置需要额外注意。

【1】防火墙操作常用命令

查询防火墙状态:

[root@localhost ~] service   iptables status

停止防火墙:

[root@localhost ~] service   iptables stop

启动防火墙:

[root@localhost ~] service   iptables start

重启防火墙:

[root@localhost ~] service   iptables restart

永久关闭防火墙:

[root@localhost ~] chkconfig   iptables off

永久关闭后启用:

[root@localhost ~] chkconfig   iptables on

【2】配置防火墙

命令如下:

vim /etc/sysconfig/iptables

添加8656端口:

Centos6下操作防火墙(iptables)_iptables


保存配置文件并执行如下命令使其生效:

[root@localhost ~]# service iptables restart

【Tips】

这里记录一个小坑,当你在iptables文件里面修改后,谨记不要使用如下命令:

servcie iptables save

如果直接编辑了配置文件,然后用​​service iptables save​​,那么内存里的配置规则是初始的,会覆盖你直接对配置文件的编辑 !

那么该命令如何使用呢?

在你使用命令修改防火墙情况下,使用该命令会使其永久有效!

iptables  -A INPUT -p tcp -m state --state NEW -m tcp --dport 82 -j ACCEPT
#上面的命令即时生效,但是重启iptables服务后就消失了

service iptables save
#iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

参考博文:
​CentOS7下关闭默认防火墙启用iptables防火墙Linux - iptables详解与实例