根據預設,Secure Web Proxy 會使用代管 Cloud NAT 閘道 (swg-autogen-nat) 處理傳出網路流量,通常會使用自動分配的 IP 位址。本頁面說明如何設定 Cloud NAT 閘道,使用您在 Google Cloud 專案中擁有及管理的一組特定靜態外部 IPv4 位址。工作負載中所有透過 Secure Web Proxy 轉送的傳出流量,都會從這些預先定義的靜態 IP 之一傳出。
為傳出流量指派靜態 IP 位址有幾項主要優點:
可預測的傳出流量來源 IP:可讓外部服務、合作夥伴和地端部署防火牆將您的特定 IP 位址新增至授權清單,確保接受來自 Secure Web Proxy 執行個體的流量。如要存取受 IP 存取控管清單 (ACL) 保護的資源,這項設定至關重要。
動態通訊埠分配 (DPA):從您為傳出流量指派的一組靜態 IP 位址中,有效率地分配可用的來源通訊埠。DPA 可讓工作負載使用有限數量的靜態 IP 管理傳出流量,不會用盡所有可用通訊埠。詳情請參閱「動態通訊埠分配」。
強化資安態勢:提供一組較小、已知的 IP 位址,方便管理及監控,簡化安全性稽核和威脅分析。
改善第三方整合服務:與 SaaS 供應商和 API 完美整合,這些供應商和 API 需要或建議使用 IP 許可清單,以強化安全性。
簡化法規遵循程序:協助您滿足所有傳出流量點及其相關聯 IP 位址的法規遵循要求。
事前準備
完成初始設定步驟。
預留一份靜態 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 位址
控制台
前往 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 gateway details」(Cloud NAT 閘道詳細資料) 頁面隨即開啟。點選「編輯」,「Edit Cloud NAT gateway」(編輯 Cloud NAT 閘道) 頁面隨即開啟。
在「Cloud NAT IP addresses」(Cloud NAT IP 位址) 部分,將設定從「Automatic (recommended)」(自動 (建議)) 變更為「Manual」(手動)。
在「IP addresses」(IP 位址) 部分,選取您預留的靜態 IP 位址。詳情請參閱「設定 Secure Web Proxy 的 Cloud NAT IP」。
如要新增多個 IP 位址,請按一下 「Add IP address」(新增 IP 位址) 按鈕。
展開「Advanced configurations」(進階設定) 專區,然後勾選「Enable Dynamic Port Allocation」(啟用動態通訊埠分配) 核取方塊。
在「Min ports per VM」(每個 VM 的通訊埠數量下限) 部分,建議輸入
2048。在「Max ports per VM」(每個 VM 的通訊埠數量上限) 部分,建議您輸入
4096。按一下「儲存」。
儲存變更後,請確認下列事項:
在 Cloud NAT 閘道詳細資料頁面中,確認「IP addresses」(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:虛擬私有雲網路名稱
輸出結果會與下列內容相似:
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:虛擬私有雲網路名稱
如要更新 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 位址資源的名稱