默认情况下,Secure Web Proxy 使用代管式 Cloud NAT 网关 (swg-autogen-nat) 处理出站 Web 流量,该网关通常使用自动分配的 IP 地址。本页面介绍了如何配置 Cloud NAT 网关,以使用您在 Google Cloud 项目中拥有和管理的一组特定静态外部 IPv4 地址。然后,通过 Secure Web Proxy 路由的工作负载的所有出站流量都源自这些预定义的静态 IP 之一。
以下是为出站流量分配静态 IP 地址的一些主要优势:
可预测的出站流量来源 IP:使外部服务、合作伙伴和本地防火墙能够将您的特定 IP 地址添加到其授权列表中,从而确保接受来自 Secure Web Proxy 实例的流量。这对于访问受基于 IP 的访问权限控制列表 (ACL) 保护的资源至关重要。
动态端口分配 (DPA):从您为出站流量分配的一组静态 IP 地址中高效分配可用源端口。借助 DPA,您的工作负载可以使用有限数量的静态 IP 管理出站流量,而不会用尽所有可用端口。如需了解详情,请参阅动态端口分配。
增强的安全状况:提供一组较小的已知 IP 地址进行管理和监控,从而简化安全审核和威胁分析。
改进了第三方集成:可与需要或建议使用 IP 许可清单以增强安全性的 SaaS 提供商和 API 无缝集成。
简化合规性:帮助您满足所有出站流量点及其关联 IP 地址的合规性要求。
准备工作
完成初始设置步骤。
预留要用于 Secure Web Proxy 实例的静态 IPv4 地址列表。在 Google Cloud中预留 IP 地址之前,请确保使用
gcloud compute addresses create命令创建地址资源。验证您是否已安装 Google Cloud CLI 406.0.0 版或更高版本:
gcloud version | head -n1如果您安装的是早期 gcloud CLI 版本,请更新版本:
gcloud components update --version=406.0.0
为 Secure Web Proxy 配置静态 IP 地址
控制台
在 Google Cloud 控制台中,前往 Cloud NAT 页面。
找到 Secure Web Proxy 实例使用的 Cloud NAT 网关。其名称为
swg-autogen-nat,并且会与相应区域和 虚拟私有云 网络中的 Cloud NAT(名称采用swg-autogen-router-YYYY格式)相关联。如需前往 Cloud NAT 网关的详情页面,请点击
swg-autogen-nat网关名称。系统会打开 Cloud NAT 网关详情页面。点击修改。系统随即会打开修改 Cloud NAT 网关页面。
对于 Cloud NAT IP 地址,将设置从自动(推荐)更改为手动。
对于 IP 地址,选择您预留的静态 IP 地址。如需了解详情,请参阅为 Secure Web Proxy 配置 Cloud NAT IP。
如需添加多个 IP 地址,请点击 添加 IP 地址按钮。
展开高级配置部分,然后选中启用动态端口分配复选框。
对于每个虚拟机的端口数下限,我们建议您输入
2048。对于每个虚拟机的端口数上限,我们建议您输入
4096。点击保存。
保存更改后,请验证以下内容:
在 Cloud NAT 网关详情页面上,检查 IP 地址部分现在是否列出了您手动选择的静态 IP 地址。
检查是否已为之前配置的每个虚拟机 (VM) 的正确端口数下限和上限启用了动态端口分配。
Cloud Shell
如需确定在预配 Secure Web Proxy 实例时分配的 Cloud Router 名称,请使用
gcloud compute routers list命令。gcloud compute routers list \ --region REGION \ --filter="network:(NETWORK_NAME) AND name:(swg-autogen-router-*)" \ --format="get(name)"替换以下内容:
REGION:为 Secure Web Proxy 实例部署 Cloud Router 路由器的区域NETWORK_NAME:您的 VPC 网络的名称
输出类似于以下内容:
swg-autogen-router-1如需列出在预配 Secure Web Proxy 实例时分配的外部自动预配 IP 地址,请使用
gcloud compute routers get-status命令。gcloud compute routers get-status ROUTER_NAME \ --region=REGION输出类似于以下内容:
kind: compute#routerStatusResponse result: natStatus: - autoAllocatedNatIps: - 34.144.80.46 - 34.144.83.75 - 34.144.88.111 - 34.144.94.113 minExtraNatIpsNeeded: 0 name: swg-autogen-nat numVmEndpointsWithNatMappings: 3 network: https://www.googleapis.com/compute/projects/PROJECT_NAME/global/networks/NETWORK_NAME此输出包括以下值:
PROJECT_NAME:您的 Google Cloud项目的名称NETWORK_NAME:您的 VPC 网络的名称
如需更新 Cloud NAT 网关以使用预定义的 IP 范围,请使用
gcloud compute routers nats update命令。gcloud compute routers nats update swg-autogen-nat \ --router=ROUTER_NAME \ --nat-external-ip-pool=IPv4_ADDRESSES... \ --region=REGION将
IPv4_ADDRESSES替换为您要使用的外部 IPv4 地址资源的名称,并用英文逗号 (,) 分隔。如需验证您的 IP 范围是否已分配给 Cloud NAT 网关,请使用
gcloud compute routers nats describe命令。gcloud compute routers nats describe swg-autogen-nat \ --router=ROUTER_NAME \ --region=REGION输出类似于以下内容:
enableEndpointIndependentMapping: false icmpIdleTimeoutSec: 30 logConfig: enable: false filter: ALL name: swg-autogen-nat natIpAllocateOption: MANUAL_ONLY natIps: - https://www.googleapis.com/compute/projects/PROJECT_NAME/regions/REGION/addresses/ADDRESS sourceSubnetworkIpRangesToNat: ALL_SUBNETWORKS_ALL_IP_RANGES此输出包括以下值:
PROJECT_NAME:您的 Google Cloud项目的名称REGION:部署 Cloud NAT 网关的区域ADDRESS:静态 IPv4 地址资源的名称
如需将 Cloud NAT 网关更新为使用动态端口分配 (DPA) 模式,请使用
gcloud compute routers nats update命令。 DPA 模式使您的 Secure Web Proxy 实例能够使用分配的 IP 地址。gcloud compute routers nats update swg-autogen-nat \ --router=ROUTER_NAME \ --min-ports-per-vm=2048 \ --max-ports-per-vm=4096 \ --enable-dynamic-port-allocation \ --region=REGION对于
--min-ports-per-vm和--max-ports-per-vm标志,我们建议您分别将其值设置为2048和4096。使用 Metrics Explorer 监控以下指标数据,并根据需要调整 DPA 最小值和最大值:
Cloud NAT Gateway - Port usageCloud NAT Gateway - New connection countCloud NAT Gateway - Open connections
如需验证 DPA 是否已启用以及是否已设置端口数下限和上限,请使用
gcloud compute routers nats describe命令。gcloud compute routers nats describe swg-autogen-nat \ --router=ROUTER_NAME \ --region=REGION检查
natIpAllocateOption: MANUAL_ONLY的输出,验证natIps列表是否包含您的静态 IP 地址。输出类似于以下内容:
enableDynamicPortAllocation: true enableEndpointIndependentMapping: false endpointTypes: - ENDPOINT_TYPE_SWG logConfig: enable: true filter: ERRORS_ONLY maxPortsPerVm: 4096 minPortsPerVm: 2048 name: swg-autogen-nat natIpAllocateOption: MANUAL_ONLY natIps: - https://www.googleapis.com/compute/projects/PROJECT_NAME/regions/REGION/addresses/ADDRESS sourceSubnetworkIpRangesToNat: ALL_SUBNETWORKS_ALL_IP_RANGES type: PUBLIC此输出包括以下值:
PROJECT_NAME:您的 Google Cloud项目的名称REGION:部署 Cloud NAT 网关的区域ADDRESS:静态 IPv4 地址资源的名称