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

命令含义:

    --zone #作用域

    --add-port=80/tcp  #添加端口,格式为:端口/通讯协议

   --permanent   #永久生效,没有此参数重启后失效

几点说明:

方法二的配置方式是间接修改/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

发布了3 篇原创文章 · 获赞 9 · 访问量 5464

猜你喜欢

转载自blog.csdn.net/NewTWG/article/details/84584564
今日推荐