CentOS7防火墙firewalld简单配置和使用
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新增一个tcp规则
firewall-cmd --permanent --zone=public --add-port=80/tcp
##Remove删除一个tcp规则
firewall-cmd --permanent --zone=public --remove-port=80/tcp
##Reload 重新读取防火墙
firewall-cmd --reload禁ping
firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'
其中,方法二的配置方式是间接修改/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
查看防火墙规则
firewall-cmd --list-all
防火墙用户配置目录
/etc/firewalld/
用户可以通过修改配置文件的方式添加端口,也可以通过命令的方式添加端口,注意,修改的内容会在/etc/firewalld/ 目录下的配置文件中还体现。
页:
[1]