跳转到内容
搜索文档

使用 IP 列表

最后更新 查看 MarkdownAgent 设置

IP 列表 是 Cloudflare 自定义列表的一部分。自定义列表包含一个或多个相同类型的项目——IP 地址、主机名或 ASN——您可以在规则表达式中引用它们。

IP 列表在账户级别进行定义,可用于与 ip.srcip.dst 字段进行匹配。目前,Cloudflare Network Firewall(前称 Magic Firewall)在这些列表中仅支持 IPv4 地址,不支持 IPv6。

要使用此功能:

1. 创建新的 IP 列表

例如:

curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists \
--header "X-Auth-Email: <EMAIL>" \
--header "X-Auth-Key: <API_KEY>" \
--header "Content-Type: application/json" \
--data '{
  "name": "iplist",
  "description": "This contains IPs that should be allowed.",
  "kind": "ip"
}'

2. 向列表中添加 IP

接下来,创建列表项。这会将元素添加到当前列表中。

curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/{list_id}/items \
--header "X-Auth-Email: <EMAIL>" \
--header "X-Auth-Key: <API_KEY>" \
--header "Content-Type: application/json" \
--data '[
  {"ip":"10.0.0.1"},
  {"ip":"10.10.0.0/24"}
]'

3. 在规则中使用列表

最后,在现有规则集中添加一条引用该列表的 Network Firewall 规则:

curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id}/rules \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
  "action": "skip",
  "action_parameters": {
    "ruleset": "current"
  },
  "expression": "ip.src in $iplist",
  "description": "Allowed IPs from iplist",
  "enabled": true
}'

托管列表 (Managed lists)

您可以使用托管列表来创建规则。托管 IP 列表是由 Cloudflare 维护并频繁更新的 IP 地址列表

当您在 Field(字段) 下拉菜单中选择 IP destination address (目标 IP 地址)IP source address (源 IP 地址),并在 Operator(运算符) 下拉菜单中选择 is in list (属于列表)is not in list (不属于列表) 时,即可访问这些托管列表。

例如:

字段 运算符
IP destination address is in list Anonymizers

这篇文档对您有帮助吗?