分流流量功能让您指定哪些应用程序应绕过 Cloudflare 的安全过滤,直接访问互联网。它通过检查 DNS 请求工作。如果您的网络缓存 DNS 请求,那么只有在缓存条目过期、客户端发出 Cloudflare One Appliance(前称 Magic WAN Connector)能够检测到的新 DNS 请求后,分流才会生效。这可能需要几分钟。
flowchart LR accTitle: Breakout traffic flow accDescr: Applications 1 and 2 are configured to bypass Cloudflare's security filtering, and go straight to the Internet. a(Cloudflare One Appliance) --> b(Cloudflare) -->|Filtered traffic|c(Internet) a-- Breakout traffic ---d(Application1) & e(Application2) --> c classDef orange fill:#f48120,color: black class a,b orange
在上图中,应用程序 1 和 2 被配置为绕过 Cloudflare 的安全过滤,直接访问互联网。
在 Cloudflare One Appliance 中添加或移除分流流量(Breakout traffic)应用程序之前,您需要一份账户级应用程序列表。该列表包含两类应用程序:
- Cloudflare 托管应用程序(Cloudflare-managed applications) — Cloudflare 内置的已识别应用程序目录。这些应用程序已存在于您的账户中,无需创建。在分配应用程序流量时直接选择即可。
- 自定义应用程序(Custom applications) — 您通过 hostname(主机名)、IP subnet(IP 子网) 和/或 source subnet(源子网) 定义的应用程序。您可以直接从仪表板或通过 Create an account app 端点创建、编辑和删除自定义应用程序。
- 转到 Connectors(连接器) 页面。
- 转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
- 选择您要配置的 Cloudflare One Appliance > Edit(编辑)。
- 选择 Traffic Steering(流量引导)。
- 在 Breakout traffic(分流流量) 中,选择 Assign application traffic(分配应用程序流量)。
- 在 Custom applications(自定义应用程序) 中,选择 Add(添加) 以创建新的自定义应用程序,并输入:
- Name(名称) — 应用程序的显示名称。
- Category(类别) — 可选的分组标签,例如
Productivity或Video conferencing。 - Hostnames(主机名)、IP subnets(IP 子网) 或 Source subnets(源子网) 中至少一项 — 用于识别此应用程序的流量。主机名必须是有效的 FQDN(例如
auth.example.com)。IP 子网和源子网必须是有效的 IPv4 CIDR(例如10.0.0.0/24)。单个地址需要/32后缀。尚不支持 IPv6。
- 选择 Add application(添加应用程序)。
- 要更改或移除现有自定义应用程序,请在 Custom applications(自定义应用程序) 表格中选择其旁边的 三个点,然后选择 Edit(编辑) 或 Delete(删除)。
发送 POST 请求以在您的账户中创建自定义应用程序。以下示例使用全部三个可选匹配条件:
Required API token permissions
At least one of the following token permissions is required:Magic WAN WriteMagic Transit Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/apps" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Example application",
"type": "Productivity",
"hostnames": [
"auth.example.com"
],
"ip_subnets": [
"192.0.2.0/24"
],
"source_subnets": [
"10.0.0.0/24"
]
}'{
"result": {
"account_app_id": "eb09v665c0784618a3e4ba9809258fd4",
"name": "Example application",
"type": "Productivity",
"hostnames": ["auth.example.com"],
"ip_subnets": ["192.0.2.0/24"],
"source_subnets": ["10.0.0.0/24"]
},
"success": true,
"errors": [],
"messages": []
}现在可以将这个新应用程序添加到 Cloudflare One Appliance 的分流流量列表。
需要为每个现有站点配置分流流量应用程序,因为这是一项按站点设置的配置。
- 转到 Connectors(连接器) 页面。
-
转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
-
选择您要配置的 Cloudflare One Appliance > Edit(编辑)。
-
选择 Traffic Steering。
-
在 Breakout traffic(分流流量) 中,选择 Assign application traffic(分配应用程序流量)。
-
从 Custom applications(自定义应用程序) 或 Cloudflare-managed applications(Cloudflare 托管应用程序) 中选择一个或多个应绕过 Cloudflare 过滤的应用程序。您也可以使用搜索框,或选择 Add(添加) 以在不离开此面板的情况下定义新的自定义应用程序 — 请参阅 创建、编辑或删除自定义应用程序。
-
(可选)还可以将应用程序固定到某个 WAN 端口。在 Preferred breakout port 中,选择要分配给应用程序的 WAN 端口。详情请参阅为分流应用程序指定 WAN 端口。
-
选择 Save(保存)。
所选应用程序的流量现在会直接访问互联网,并绕过 Cloudflare 的过滤。
-
发送
GET请求,列出与账户关联的应用程序。
At least one of the following token permissions is required:Required API token permissions
Magic WAN WriteMagic WAN ReadMagic Transit ReadMagic Transit Write
List Appsbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/apps" \ --request GET \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{ "result": [ { "managed_app_id": "<APP_ID>", "name": "<APP_NAME>", "type": "File Sharing", "hostnames": [ "<app_name.com>", "<app-name.info>" ] } ] }记下要添加的每个应用程序的
"managed_app_id"值。 -
发送
POST请求,将新应用程序添加到分流流量策略。
At least one of the following token permissions is required:Required API token permissions
Magic WAN WriteMagic Transit Write
Create a new App Configbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/app_configs" \ --request POST \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "managed_app_id": "<MANAGED_APP_ID>", "breakout": true }'{ "result": { "account_app_id": "<APP_ID>", "name": "<APP_NAME>", "type": "<BREAKOUT_OR_PRIORITY>" }, "success": true, "errors": [], "messages": [] }
- 转到 Connectors(连接器) 页面。
-
转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
-
选择要配置的 Appliance > Edit。
-
选择 Traffic Steering。
-
在 Breakout traffic 中找到要删除的应用程序,选择其旁边的 three dots,再选择 Remove application traffic。
-
(可选)如果应用程序列表有多页,可以使用搜索框快速查找目标应用程序。
需要从每个现有站点删除分流流量应用程序,因为这是一项按站点设置的配置。
-
发送
GET请求,列出与站点关联的应用程序。
At least one of the following token permissions is required:Required API token permissions
Magic WAN WriteMagic WAN ReadMagic Transit ReadMagic Transit Write
List App Configsbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/app_configs" \ --request GET \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{ "result": [ { "id": "<APP_ID>", "site_id": "<SITE_ID>", "managed_app_id": "<APP_NAME>", "breakout": true } ] }记下要删除的应用程序的
"id"值。 -
发送
DELETE请求,从分流流量策略删除应用程序。curl "https://api.cloudflare.com/client/v4/accounts/%7Baccount_id%7D/magic/sites/%7Bsite_id%7D/app_configs/%7Bid%7D" \ --request DELETE{ "result": { "id": "<APP_ID>", "site_id": "<SITE_ID>", "managed_app_id": "<APP_NAME>", "breakout": true }, "success": true, "errors": [], "messages": [] }
如果需要控制应用程序从设备上的哪个 WAN 端口传出,可以在 Cloudflare One Appliance 中将应用程序固定到指定 WAN 端口。如果首选 WAN 端口故障,Cloudflare One Appliance 会按照标准配置的 WAN 端口优先级自动故障转移。
通过首选分流端口,客户可以直接控制本地互联网分流流量。您可以将特定 WAN 上行链路指定为关键应用程序绕过 Cloudflare 网络时的主要路径。这样,性能敏感的应用程序便能获得所需的可预测性和控制能力,确保关键流量始终走您选择的路径。
要将应用程序固定到 WAN 端口:
- 转到 Connectors(连接器) 页面。
-
转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
-
选择您要配置的 Cloudflare One Appliance > Edit(编辑)。
-
在 Traffic steering > Breakout Traffic 中找到要固定到 WAN 端口的应用程序。
-
选择其旁边的三个点 > Edit application traffic。
-
从 Preferred breakout port 下拉菜单中选择要分配给应用程序的 WAN 端口。
-
选择 Save(保存)。
您可以配置 Cloudflare One Appliance(前称 Magic WAN Connector),将本地分流流量的 NetFlow 统计数据导出到 Network Flow(前称 Magic Network Monitoring)。这样可以查看直接从站点传出、绕过 Cloudflare 网络的流量。
Cloudflare One Appliance 使用 NetFlow v9 仅导出本地流转流量的流数据(flow data)。您可以通过 Cloudflare API 设置关联站点的 NetFlow 配置来启用并配置此导出。
- 向您站点的 NetFlow 配置端点发送
PUT请求。 - 在 JSON 请求体中,您必须包含
collector_ip参数。要将流量统计信息导出到 Network Flow,请使用 IP 地址162.159.65.1。这是启用该功能所需的唯一字段。
最小配置示例:
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/netflow_config" \
--request PUT \
--json '{
"collector_ip": "162.159.65.1"
}'- 您可以通过向 JSON 负载中添加可选字段来自定义配置。这些字段包括:
collector_port:收集器的 UDP 端口。默认值为2055。sampling_rate:数据包采样率。active_timeout:活动流的超时时间(以秒为单位)。inactive_timeout:非活动流的超时时间(以秒为单位)。
完整配置示例:
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/netflow_config" \
--request PUT \
--json '{
"collector_ip": "162.159.65.1",
"collector_port": 2055,
"sampling_rate": 100,
"active_timeout": 60,
"inactive_timeout": 30
}'您的 Cloudflare One Appliance 现在将开始导出其本地流转流量的 NetFlow 数据,这些数据将被摄取并显示在您的 Network Flow 仪表板中。您可以通过发送 GET 请求来检索当前设置,或者通过向同一端点发送 DELETE 请求来禁用导出。
如果您的场所中部署了 Cloudflare One Appliance(前称 Magic WAN Connector)和 Cloudflare One Client,则 Cloudflare One Appliance 会自动将 Cloudflare One Client 流量路由到互联网,而不是 Cloudflare WAN IPsec 隧道。这可以防止流量被封装两次。
您可能需要配置防火墙以允许此新流量。确保允许以下 IP 和端口:
- Destination IPs(目的 IP):
162.159.193.0/24、162.159.197.0/24 - Destination ports(目的端口):
443、500、1701、2408、4443、4500、8095、8443
有关详细信息,请参阅在防火墙中使用 Cloudflare One Client。
除了按目标应用程序进行匹配之外,您还可以定义按源(按源 LAN 接口、源 VLAN 或源 IP 地址 / CIDR 块)进行匹配的突围规则。这对于将整个访客 VLAN 或特定子网突围到本地互联网非常有用,而无需枚举目标应用程序。
| 条件 | 行为 | 配置方式 |
|---|---|---|
| 源 LAN 接口 | 发源于所选 LAN 的所有流量均被突围。任何连接到该 LAN 的 VLAN 都会自动包含在内。 | API 和 Terraform。 |
| 源 IPv4 CIDR | 源 IP 位于指定 CIDR 块内的所有流量均被突围。 | 仪表板(自定义应用程序 上的 Source subnets(源子网) 字段)、API 和 Terraform。 |
| 源 IP 地址或范围 | 源 IP 匹配指定地址或范围的所有流量均被突围。 | API 和 Terraform。 |
可以使用相同的条件将流量标记为优先 而不是突围。有关详细信息,请参阅优先流量。
基于源和基于目标(托管应用程序或自定义应用程序)的规则可以共存于同一设备上,并且会独立进行评估。如果流同时匹配基于源的突围规则和基于目标的突围规则,设备将对其进行突围。