firewall

#一、介绍

防火墙守护 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

现在IP访问

对指定ip进行放通

firewall 现在网段访问

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维螺丝钉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值