一、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 #防火墙处于关闭状态
注意:
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