Firewalld 白名单配置方法

This guide explains how to configure a firewall to only trust connections from specified IP ranges. It includes steps on adding IP address ranges to the trusted zone, setting the default zone to drop, and assigning network interfaces.

1. 白名单配置方法

以仅信任来自 10.60.22.0/24, 10.60.23.0/24 ip 端的连接为例

1.1 配置信任来源

1
2
3
# 添加 IP 地址范围到 "trusted" 的区域
firewall-cmd --permanent --zone=trusted --add-source=10.60.22.0/24
firewall-cmd --permanent --zone=trusted --add-source=10.60.23.0/24

1.2 配置默认拒绝

1
2
3
4
# 将默认的防火墙区域设置为 "drop"
firewall-cmd --set-default-zone=drop
# 将网络接口 eth0 分配给 "drop" 区域
firewall-cmd --permanent --zone=drop --change-interface=eth0

1.3 Reload 防火墙

1
2
firewall-cmd --reload
firewall-cmd --get-active-zones

get-active-zones 应该会得到类似如下配置

1
2
3
4
drop
  interfaces: eth0
trusted
  sources: 10.60.22.0/24 10.60.23.0/24
使用 Hugo 构建
主题 StackJimmy 设计