解决CentOS6、7,/etc/sysconfig/下没有iptables的问题

一、Centos 6版本解决办法:

1.任意运行一条iptables防火墙规则配置命令:

iptables -P OUTPUT ACCEPT  

2.对iptables服务进行保存:

service iptables save  

3.重启iptables服务:

service iptables restart 

 

查看防火墙的状态:

[root@localhost ~]# service iptable status 

保存退出后重启防火墙

[root@localhost ~]# service iptables restart

关闭防火墙

[root@localhost ~]#servcie iptables stop                    --临时关闭防火墙

[root@localhost ~]#chkconfig iptables off                    --永久关闭防火墙 

 

centos 6 开放80端口

vim /etc/sysconfig/iptables
# 加入如下代码,只需要把端口修改一下就变成了其他的,然后service iptables restart重启
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

 

二、Centos 7版本解决办法:

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
 

1、停止并屏蔽firewalld服务

systemctl stop firewalld
systemctl mask firewalld

2、安装iptables-services软件包

yum install iptables-services

3、在引导时启用iptables服务

systemctl enable iptables

4、启动iptables服务

systemctl start iptables

5、保存防火墙规则

service iptables save
或
/usr/libexec/iptables/iptables.init save

另外:管理iptables服务

systemctl [stop|start|restart] iptables

 

centOS 7防火墙:

 

firewall-cmd --query-port=8080/tcp                                # 查询端口是否开放

firewall-cmd --permanent --add-port=80/tcp                   # 开放80端口    

firewall-cmd --permanent --remove-port=8080/tcp          # 移除端口

 

 

[root@localhost ~]# systemctl stop firewalld.service                   #停止/关闭firewall

[root@localhost ~]# systemctl disable firewalld.service          #禁止firewall开机启动

[root@localhost ~]# firewall-cmd --reload            #重启

 

服务

[root@localhost ~]# systemctl enable firewalld.service    #在开机时启用一个服务

[root@localhost ~]# systemctl disable firewalld.service    #在开机时禁用一个服务

[root@localhost ~]#  systemctl is-enabled firewalld.service   #查看服务是否开机启动

[root@localhost ~]#  systemctl list-unit-files|grep enabled    #查看已启动的服务列表

[root@localhost ~]# firewall-cmd --list-ports             #查看防火墙的端口有没有打开

 

查看firewall的状态

[root@localhost ~]# systemctl status firewalld                   #查看防火墙状态

[root@localhost ~]# firewall-cmd --state                         #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

 

[root@localhost ~]# systemctl list-unit-files | grep firewalld.service    #检查防火墙的状态

firewalld.service                          disabled      #防火墙处于关闭状态

 

bb3f1a69a02322f0c7732f9cec7d1553006.jpg

79143f4342929111efb0bc0a83520f39efd.jpg

 

 

 

注意:

1、打开所有的端口    

iptables -P OUTPUT ACCEPT

2、关闭有的端口    

iptables -P INPUT ACCEPT

 

 

其他参考链接:http://songbgi.iteye.com/blog/1703583

https://www.linuxidc.com/Linux/2016-12/138979.htm

RedHat 7:https://www.cnblogs.com/shiguotao-com/p/4562137.html

iptables其他的使用方法:https://www.linuxidc.com/Linux/2015-05/117473.htm

 

转载于:https://my.oschina.net/u/3803405/blog/1831668

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值