跳转到内容
搜索文档

网络分段

最后更新 查看 MarkdownAgent 设置

您可以在 Cloudflare One Appliance(前称 Magic WAN Connector)中定义策略,既可以允许流量在您的 LAN 之间流动而不离开您的本地场所,也可以通过 Cloudflare 网络转发该流量(您可以在该网络中添加额外的安全功能)。默认行为是丢弃所有 LAN 到 LAN 的流量。可以针对特定子网创建这些策略,并连接两个 LAN。

	flowchart LR
	accTitle: LAN 到 LAN 流量流向
	accDescr: 在此示例中,红色路径显示保留在客户场所内的流量(允许 LAN 3 和 LAN 4 之间直接通信),橙色路径显示先流向 Cloudflare 然后返回客户场所的流量(在 Cloudflare 中处理 LAN 1 和 LAN 2 之间的流量)。
			a(Cloudflare One Appliance) <---> b(互联网) <---> c(Cloudflare)

			subgraph 客户场所
			d[LAN 1] <---> a
			e[LAN 2] <---> a
			g[LAN 3] <---> a
			h[LAN 4] <---> a
			end
			classDef orange fill:#f48120,color: black
			class a,c orange

			linkStyle 0,1,2,3 stroke:#f48120,stroke-width:3px
			linkStyle 4,5 stroke:red,stroke-width:3px

在此示例中,红色路径显示保留在客户场所内的流量(允许 LAN 3 和 LAN 4 之间直接通信),橙色路径显示先流向 Cloudflare 然后返回客户场所的流量(在 Cloudflare 中处理 LAN 1 和 LAN 2 之间的流量)。


作为安全的最佳实践,我们建议通过 Cloudflare 的网络发送所有流量,以进行 Zero Trust 安全过滤。请谨慎使用这些策略,且仅在您对 LAN 到 LAN 流量流有硬性要求的情况下使用。

如果您启用了 LAN 到 LAN 流量流,则只能从源向目的地发起通信(例如 LAN 1 到 LAN 2),而不能反向发起。这是设计使然,可以防止潜在的信息外泄。这并不意味着 TCP 上的双向通信是不可能的。它仅意味着源是唯一被授权发起通信的一方。

可以为 UDP 和 ICMP 启用单向通信,但对于 TCP 不可用,因为这会破坏该协议。

以下指南假定您已经创建了站点并配置了您的 Cloudflare One Appliance。有关创建站点和配置您的 Cloudflare One Appliance 的说明,请参阅配置硬件设备配置虚拟设备(取决于您在场所中拥有的 Cloudflare One Appliance 类型)。

创建策略

按照以下步骤创建一个新的 LAN 策略以对您的网络进行分段。只有标有 required(必填) 的字段是强制性的。

  1. 登录 Cloudflare One,并转到 Networks(网络)
  2. 转到 Connectors(连接器) > Appliances(设备) > Profiles(配置文件)
  1. 选择您要配置的 Cloudflare One Appliance > Edit(编辑)
  2. 转到 Network Configuration(网络配置) > LAN configuration(LAN 配置)
  3. 选择 LAN policies(LAN 策略) > Create
  4. Policy name 中,为正在创建的策略输入一个描述性的名称。
  5. 从下拉菜单 Origin (required) 中,选择您的源 LAN。
  6. Subnets 中为您的第一个 LAN 指定子网。
  7. Ports 中指定您想要使用的 TCP/UDP 端口。有效端口范围为 165535。零 (0) 不是有效的端口号。添加逗号以分隔每个端口,或添加端口范围。例如 2,5,6,9-14
  8. Destination (required) 中,选择目标 LAN 并重复上述过程进行配置。
  9. Protocols(协议) 中,选择您想要允许的流量类型。您可以选择 TCPUDPICMP。您也可以选择 Any(任意) 以选择所有流量类型。
  10. Traffic direction 中,您可以在双向流量(默认)和单向流量之间进行选择。您可以选择什么取决于您为该策略选择的协议:
    • Any(任意):如果选择了 Any(任意) 且您选择 Unidirectional(单向),系统将提醒您这会中断 TCP 流量。
    • TCP:您只能选择 Bidirectional(双向)
    • UDP:系统默认选择 Bidirectional(双向),但您可以选择 Unidirectional(单向)
    • ICMP:系统默认选择 Bidirectional(双向),但您可以选择 Unidirectional(单向)
  11. Traffic path(流量路径) 中,如果您希望流量被转发到 Cloudflare 进行处理,请选择 Forwarded via Cloudflare(通过 Cloudflare 转发)。如果您不选择此选项,流量将在您的场所本地流动,而不会通过 Cloudflare。
  12. 选择 Save(保存)

使用 API 创建 POST 请求以创建网络策略。

示例:

Required API token permissions

At least one of the following token permissions is required:
  • Magic WAN Write
  • Magic Transit Write
Create a new Site ACLbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/acls" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"description": "<POLICY_DESCRIPTION>",
		"forward_locally": true,
		"lan_1": {
				"lan_id": "<LAN_ID>",
				"lan_name": "<LAN_NAME>",
				"ports": [
						1
				],
				"subnets": [
						"192.0.2.1"
				]
		},
		"lan_2": {
				"lan_id": "<LAN_ID>",
				"lan_name": "<LAN_NAME",
				"ports": [
						1
				],
				"subnets": [
						"192.0.2.1"
				]
		},
		"name": "<POLICY_NAME>",
		"protocols": [
				"tcp"
		]
	}'
{
  "errors": [
    {
      "code": 1000,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message"
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "description": "Allows local traffic between PIN pads and cash register.",
    "forward_locally": true,
    "lan_1": {
      "lan_id": "lan_id",
      "lan_name": "lan_name",
      "port_ranges": [
        "8080-9000"
      ],
      "ports": [
        1
      ],
      "subnets": [
        "192.0.2.1"
      ]
    },
    "lan_2": {
      "lan_id": "lan_id",
      "lan_name": "lan_name",
      "port_ranges": [
        "8080-9000"
      ],
      "ports": [
        1
      ],
      "subnets": [
        "192.0.2.1"
      ]
    },
    "name": "PIN Pad - Cash Register",
    "protocols": [
      "tcp"
    ],
    "unidirectional": true
  },
  "success": true
}

请注意 id 参数,因为您在编辑或删除网络策略时会需要它。

新策略将确保指定 LAN 之间的流量在本地流动,绕过 Cloudflare。

编辑策略

  1. 登录 Cloudflare One,并转到 Networks(网络)
  2. 转到 Connectors(连接器) > Appliances(设备) > Profiles(配置文件)
  1. 选择您要配置的 Cloudflare One Appliance > Edit(编辑)
  2. 转到 Network Configuration(网络配置) > LAN configuration(LAN 配置)
  3. 选择 LAN policies(LAN 策略)
  4. 选择您需要编辑的策略 > Edit(编辑)
  5. 进行更改,然后选择 Update policy(更新策略)

使用 API 创建 PUT 请求以编辑网络策略。

示例:

Required API token permissions

At least one of the following token permissions is required:
  • Magic WAN Write
  • Magic Transit Write
Update Site ACLbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/acls/$ACL_ID" \
	--request PUT \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"description": "<POLICY_DESCRIPTION>",
		"forward_locally": true,
		"lan_1": {
				"lan_id": "<LAN_ID>",
				"lan_name": "<LAN_NAME>",
				"ports": [
						1
				],
				"subnets": [
						"192.0.2.1"
				]
		},
		"lan_2": {
				"lan_id": "<LAN_ID>",
				"lan_name": "<LAN_NAME>",
				"ports": [
						1
				],
				"subnets": [
						"192.0.2.1"
				]
		},
		"name": "<POLICY_NAME>",
		"protocols": [
				"tcp"
		]
	}'
{
  "errors": [
    {
      "code": 1000,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message"
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "connector_id": "ac60d3d0435248289d446cedd870bcf4",
    "description": "description",
    "ha_mode": true,
    "location": {
      "lat": "37.6192",
      "lon": "122.3816"
    },
    "name": "site_1",
    "secondary_connector_id": "8d67040d3835dbcf46ce29da440dc482"
  },
  "success": true
}

删除策略

  1. 登录 Cloudflare One,并转到 Networks(网络)
  2. 转到 Connectors(连接器) > Appliances(设备) > Profiles(配置文件)
  1. 选择您要配置的 Cloudflare One Appliance > Edit(编辑)
  2. 转到 Network Configuration(网络配置) > LAN configuration(LAN 配置)
  3. 选择 LAN policies(LAN 策略)
  4. 选择您需要编辑的策略 > Edit(编辑)
  5. 选择 Delete(删除)
  6. 在对话框中选择 I understand that deleting a policy is permanent(我理解删除策略是永久性的) > Delete(删除)

使用 API 创建 DELETE 请求以删除网络策略。

示例:

Required API token permissions

At least one of the following token permissions is required:
  • Magic WAN Write
  • Magic Transit Write
Delete Site ACLbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/acls/$ACL_ID" \
	--request DELETE \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

这篇文档对您有帮助吗?