本文說明如何指派企業 IP 位址或靜態 IP 位址,讓安全 Web Proxy 用於外送流量。 Google Cloud
事前準備
完成初始設定步驟。
請確認您已保留靜態 IPv4 位址清單,以便用於 Secure Web Proxy。如要在 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 位址
請執行下列步驟:
找出在安全網路 Proxy 佈建期間指派的 Cloud Router 名稱:
gcloud compute routers list \ --region REGION \ --filter="network:(NETWORK_NAME) AND name:(swg-autogen-router-*)" \ --format="get(name)"更改下列內容:
REGION:Cloud Router 為 Secure Web Proxy 部署的區域NETWORK_NAME:虛擬私有雲網路名稱
輸出結果會與下列內容相似:
swg-autogen-router-1列出在安全網路 Proxy 佈建期間,自動佈建的 IP 位址:
gcloud compute routers get-status ROUTER_NAME \ --region=REGION輸出結果會與下列內容相似:
,自動向上或向下調整已佈建的 Cloud NAT IP 位址。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更新 Cloud NAT 閘道,以便使用預先定義的 IP 範圍:
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 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更新 Cloud NAT 閘道,以便使用動態通訊埠分配 (DPA) 模式。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 swg-autogen-nat \ --router=ROUTER_NAME \ --region=REGION輸出結果會與下列內容相似:
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