当前位置: > CentOS > CentOS运维 >

CentOS7防火墙firewalld容易配置和使用

时间:2016-05-04 23:25来源:linux.it.net.cn 作者:IT
CentOS7防火墙firewalld简单配置和使用

    网上找了好多文章,关于CentOS7的防火墙配置和使用,都没有比较理想的说明firewalld的用法,还有一些网上摒弃centos7 firewalld防火墙,使用旧版本的iptables的替代的做法,这里笔者非常不赞同其再使用iptables。

    CentOS7使用的是Linux Kernel 3.10.0的内核版本,新版的Kernel内核已经有了防火墙netfilter,并且firewalld的使用效能更高,稳定性更好

        CentOS7配置防火墙的两种方法:

    一、使用xml配置文件的方式配置;

方法一
cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/
firewall-cmd --reload

    二、使用命令的方式配置;

方法二
##Add
firewall-cmd --permanent --zone=public --add-port=80/tcp

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

##Reload
firewall-cmd --reload

 

   其中,方法二的配置方式是间接修改/etc/firewalld/zones/public.xml文件,方案一也需要在public.xml里面新增<service name="http"/>,否则http的防火墙规则不会生效,而且两种配置方式都需要重新载入防火墙。

   附:

查看防火墙状态

 

systemctl status firewalld.service

 

启动防火墙

 

systemctl start firewalld.service

 

关闭防火墙

 

systemctl stop firewalld.service

 

重新启动防火墙

 

systemctl restart firewalld.service

 




(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容