跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

分流流量

最后更新 查看 MarkdownAgent 设置

分流流量功能让您指定哪些应用程序应绕过 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 中添加或移除分流流量应用程序之前,您需要在账户级别创建包含待配置应用程序的列表。目前,只能通过 API 的 managed_app_id 端点向此列表添加应用程序或修改列表。

要向账户添加应用程序:

发送 POST 请求,将新应用程序添加到账户。

Required API token permissions

At least one of the following token permissions is required:
  • Magic WAN Write
  • Magic Transit Write
Create a new Appbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"managed_app_id": "<APP_ID>",
		"name": "<APP_NAME>",
		"type": "<APP_TYPE>"
	}'
{
	"result": {
		"account_app_id": "eb09v665c0784618a3e4ba9809258fd4",
		"name": "<APP_NAME>",
		"type": "<APP_TYPE>",
	},
	"success": true,
	"errors": [],
	"messages": []
}

现在可以将这个新应用程序添加到 Cloudflare One Appliance 的分流流量列表。

将应用程序添加到 Cloudflare One Appliance

需要为每个现有站点配置分流流量应用程序,因为这是一项按站点设置的配置。

  1. 登录 Cloudflare One 仪表板 ↗,然后前往 Networks。

  2. 前往 Connectors > Appliances > Profiles。

  3. 选择您要配置的 Cloudflare One Appliance > Edit(编辑)。

  4. 选择 Traffic Steering。

  5. 在 Breakout traffic 中,选择 Create。

  6. 从列表中选择一个或多个应绕过 Cloudflare 过滤的应用程序。您也可以使用搜索框。

  7. (可选)还可以将应用程序固定到某个 WAN 端口。在 Preferred breakout port 中,选择要分配给应用程序的 WAN 端口。详情请参阅为分流应用程序指定 WAN 端口。

  8. 选择 Save(保存)。

所选应用程序的流量现在会直接访问互联网,并绕过 Cloudflare 的过滤。

  1. 发送 GET 请求,列出与账户关联的应用程序。

    Required API token permissions

    At least one of the following token permissions is required:
    • Magic WAN Write
    • Magic WAN Read
    • Magic Transit Read
    • Magic 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" 值。

  2. 发送 POST 请求,将新应用程序添加到分流流量策略。

    Required API token permissions

    At least one of the following token permissions is required:
    • Magic WAN Write
    • Magic 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": []
    }

从 Cloudflare One Appliance 删除应用程序

  1. 登录 Cloudflare One 仪表板 ↗,然后前往 Networks。

  2. 前往 Connectors > Appliances > Profiles。

  3. 选择要配置的 Appliance > Edit。

  4. 选择 Traffic Steering。

  5. 在 Breakout traffic 中找到要删除的应用程序,选择其旁边的 three dots,再选择 Remove application traffic。

  6. (可选)如果应用程序列表有多页,可以使用搜索框快速查找目标应用程序。

需要从每个现有站点删除分流流量应用程序,因为这是一项按站点设置的配置。

  1. 发送 GET 请求,列出与站点关联的应用程序。

    Required API token permissions

    At least one of the following token permissions is required:
    • Magic WAN Write
    • Magic WAN Read
    • Magic Transit Read
    • Magic 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" 值。

  2. 发送 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 端口

如果需要控制应用程序从设备上的哪个 WAN 端口传出,可以在 Cloudflare One Appliance 中将应用程序固定到指定 WAN 端口。如果首选 WAN 端口故障,Cloudflare One Appliance 会按照标准配置的 WAN 端口优先级自动故障转移。

通过首选分流端口,客户可以直接控制本地互联网分流流量。您可以将特定 WAN 上行链路指定为关键应用程序绕过 Cloudflare 网络时的主要路径。这样,性能敏感的应用程序便能获得所需的可预测性和控制能力,确保关键流量始终走您选择的路径。

要将应用程序固定到 WAN 端口:

  1. 登录 Cloudflare One 仪表板 ↗,然后前往 Networks。

  2. 前往 Connectors > Appliances > Profiles。

  3. 选择您要配置的 Cloudflare One Appliance > Edit(编辑)。

  4. 在 Traffic steering > Breakout Traffic 中找到要固定到 WAN 端口的应用程序。

  5. 选择其旁边的三个点 > Edit application traffic。

  6. 从 Preferred breakout port 下拉菜单中选择要分配给应用程序的 WAN 端口。

  7. 选择 Save(保存)。

从 Cloudflare One Appliance 导出 NetFlow 到 Network Flow

您可以配置 Cloudflare One Appliance(前称 Magic WAN Connector),将本地分流流量的 NetFlow 统计数据导出到 Network Flow(前称 Magic Network Monitoring)。这样可以查看直接从站点传出、绕过 Cloudflare 网络的流量。

Cloudflare One Appliance 使用 NetFlow v9 仅导出本地流转流量的流数据(flow data)。您可以通过 Cloudflare API 设置关联站点的 NetFlow 配置来启用并配置此导出。

启用 NetFlow 导出

  1. 向您站点的 NetFlow 配置端点发送 PUT 请求。
  2. 在 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"
	}'
  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 Client 流量

如果您的场所中部署了 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。

这篇文档对您有帮助吗?