#一、介绍
防火墙守护 firewalld 服务引入了一个信任级别的概念来管理与之相关联的连接与接口。它支持 ipv4 与 ipv6,并支持网桥,采用 firewall-cmd (command) 或 firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则,并实时生效而无需重启服务。
Firewall 能将不同的网络连接归类到不同的信任级别,Zone 提供了以下几个级别
drop: 丢弃所有进入的包,而不给出任何响应
block: 拒绝所有外部发起的连接,允许内部发起的连接
public: 允许指定的进入连接
external: 同上,对伪装的进入连接,一般用于路由转发
dmz: 允许受限制的进入连接
work: 允许受信任的计算机被限制的进入连接,类似 workgroup
home: 同上,类似 homegroup
internal: 同上,范围针对所有互联网用户
trusted: 信任所有连接
##1.起动服务:
[root@seliunx ~]# systemctl restart firewalld.service
##2.查看帮助信息:
[root@seliunx ~]# firewall-cmd --help
##3.如果需要图形界面的话,则再安装
yum install firewall-config
##4.查看所有的防火墙略(即显示/etc/firewalld/zones/下的所有策略)
[root@seliunx ~]# firewall-cmd --list-all-zones
##5.查看防火墙的版本
[root@seliunx ~]# firewall-cmd --version
0.4.4.4
##6.查看防火墙的运行状态
[root@seliunx ~]# firewall-cmd --state
running
##7.查看防火墙的区域信息
[root@seliunx ~]# firewall-cmd --get-active-zones //已经生效的防火墙区域
public
interfaces: eth0
[root@seliunx ~]# firewall-cmd --get-zones //查看所有的防火墙区域
block dmz drop external home internal public trusted work
8.查看指定接口的区域信息:
[root@seliunx ~]# firewall-cmd --get-zone-of-interface=eth0
public
##9.开启拒绝所有的数据包
[root@seliunx ~]# firewall-cmd --panic-on
success
##10.关闭拒绝所有数据包
[root@seliunx ~]# firewall-cmd --panic-off
success
##11.查看是否拒绝
[root@seliunx ~]# firewall-cmd --query-panic
no
##12.将默认区域改为trusted
[root@seliunx ~]# firewall-cmd --get-default-zone
public
[root@seliunx ~]# firewall-cmd --set-default-zone=trusted
success
[root@seliunx ~]# firewall-cmd --get-default-zone
trusted
##13.添加一个网段阻止访问数据库
[root@seliunx ~]# firewall-cmd --permanent --zone=block --add-source=176.121.0.0/24 (//permanent 是永久配置的意思)
success
[root@seliunx ~]# firewall-cmd --reload //重新加载防火墙,也加升级防火墙配置
success
[root@seliunx ~]# firewall-cmd --list-all --zone=block //查看指定区域的全部配置信息
##13.查看生效的区域
[root@seliunx ~]# firewall-cmd --get-active-zones
##14.开启端口转发
[root@seliunx ~]# firewall-cmd --permanent --zone=trusted --add-forward-port=port=5423:proto=tcp:toport=80
success
[root@seliunx ~]# firewall-cmd --reload
success
[root@seliunx ~]# firewall-cmd --list-all
##15.关闭端口转发
[root@seliunx ~]# firewall-cmd --permanent --zone=trusted --remove-forward-port=port=5423:proto=tcp:toport=80
success
[root@seliunx ~]# firewall-cmd --reload
success
[root@seliunx ~]# firewall-cmd --list-all
1、查看防火墙是否运行
[root@node2 ~]# firewall-cmd --state
2、查看区域
[root@node2 ~]# firewall-cmd --get-zones
trusted: 进入该区域数据包,放行
block: 进入该区域数据包,拒绝
drop: 进入该区域数据包,丢弃
其他区域除明确允许的以外,默认拒绝
3、查看生效的区域
[root@node2 ~]# firewall-cmd --get-active-zones
4、数据包进入哪个区域
(1)匹配数据包的源IP地址
[root@node2 ~]# firewall-cmd --add-source=192.168.1.0/24 --zone=dmz
(2)根据数据包从哪块网卡收到
[root@node2 ~]# firewall-cmd --add-interface=eth1 --zone=work
(3)默认区域
[root@node2 ~]# firewall-cmd --get-default-zone
[root@node2 ~]# firewall-cmd --set-default-zone=home
5、允许访问http服务
[root@node2 ~]# firewall-cmd --add-service=http --zone=home
[root@node2 ~]# firewall-cmd --add-port=8090/tcp --zone=home
firewall 放通某一网段进行访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.153.83.48/29" port protocol="tcp" port="9092" accept"
firewall-cmd --restore
firewall-cmd --zone=pubic --remove=port="10000/tcp" --permanent
firewall-cmd --zone=pubic --remove=port="11000/tcp" --permanent
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.153.83.0/24" port protocol="tcp" port="10000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.153.83.0/24" port protocol="tcp" port="11000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.33.0/24" port protocol="tcp" port="10000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.33.0/24" port protocol="tcp" port="11000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.35.0/24" port protocol="tcp" port="10000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.45.0/24" port protocol="tcp" port="11000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.45.0/24" port protocol="tcp" port="10000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.35.0/24" port protocol="tcp" port="11000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.101.40.0/24" port protocol="tcp" port="10000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.101.40.0/24" port protocol="tcp" port="11000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.3.14.0/24" port protocol="tcp" port="10000" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.3.14.0/24" port protocol="tcp" port="11000" accept"
firewall-cmd --reload
firewall-cmd --list-all