在Linux Centos 6与Centos 7中该如何关闭或开启防火墙

在Linux Centos 6与Centos 7中该如何关闭或开启防火墙呢?因为Linux防火墙很重要,比如我们的web网站服务器或SVN如果要让外部直接访问,就得关闭防火墙,否则网页就会出错,无法访问。

在Centos 6服务器中关闭或开启防火墙的方法,使用service命令,分别如下:

查询防火墙状态    :    [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

那么在Centos 6中如何只开启某个端口的防火墙呢?以开启8080端口为例,请运行如下命令:

//开启8080端口防火墙
sudo iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT

//保存设置
sudo service iptables save

注意:此设置并不是永久性的,Linux重启之后会恢复以前的设置。

在Centos7中关闭或开启防火墙的方法,使用systemctl命令,如下:

永久关闭防火墙:systemctl disable firewalld
开启防火墙:systemctl start firewalld
关闭防火墙:systemctl stop firewalld
重启防火墙:systemctl reload firewalld
查询防火墙状态:systemctl status firewalld那怎么开启一个端口呢

添加

firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone= public --query-port=80/tcp

删除

firewall-cmd --zone= public --remove-port=80/tcp --permanent

注意:在开启某个端口的防火墙时,如果没有“--permanent”标识,则标识它不是永久开启的,在服务器重启之后会恢复之前的设置。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值