為 Secure Web Proxy 使用 Cloud NAT

佈建 Secure Web Proxy 執行個體時,系統會在相同區域和虛擬私有雲 (VPC) 網路中,自動建立 Cloud NAT 閘道。接著,這個閘道會將私人 IP 對應至公開 IP,藉此管理網際網路存取權,確保所有來自安全網路 Proxy 執行個體的輸出網路流量都能連上網際網路。

根據預設,這個自動佈建的 Cloud NAT 閘道會設為 Automatic NAT IP address allocation。這表示系統會動態指派及調整 Secure Web Proxy 執行個體使用的公開 IP 位址。 Google Cloud不過,您可以重新設定這個閘道,使用一組靜態公開 IP 位址,並手動保留及指派這些位址。

事前準備

  • 完成初始設定步驟

  • 找出部署 Secure Web Proxy 執行個體的 VPC 網路和區域。

  • 確認您已安裝 Google Cloud CLI 406.0.0 以上版本:

    gcloud version | head -n1
    

    如果您安裝的是舊版 gcloud CLI,請更新版本:

    gcloud components update --version=406.0.0
    

設定安全網路 Proxy 的 Cloud NAT IP

控制台

  1. 如要預留一組特定的靜態外部 IP 位址,請按照下列步驟操作:

    1. 前往 Google Cloud 控制台的「IP addresses」(IP 位址) 頁面。

      前往「IP addresses」(IP 位址) 頁面

    2. 按一下「保留外部」。系統會開啟「Reserve external static IP address」(預留外部靜態 IP 位址)頁面。

    3. 在「Name」(名稱) 欄位中輸入 IP 位址名稱,例如 swp-nat-ip-1

    4. 在「Description」(說明) 欄位中輸入 IP 位址的說明。

    5. 在「網路服務級別」中,選取所需選項。

    6. 將「IP version」(IP 版本) 設為「IPv4」

    7. 在「Type」(類型) 中,選取「Regional」(地區)。

    8. 在「Region」(區域) 中,選取部署 Secure Web Proxy 執行個體的相同區域。

    9. 在「Attached」(已附加) 部分,將選取項目保留為「None」(無)

    10. 按一下「預訂」。針對要用於 Cloud NAT 閘道的每個靜態 IP 位址,重複執行這個程序。

  2. 如要找出並修改 Secure Web Proxy 執行個體的 Cloud NAT 閘道,請按照下列步驟操作:

    1. 前往 Google Cloud 控制台的「Cloud NAT」頁面。

      前往 Cloud NAT

    2. 找出 Secure Web Proxy 執行個體使用的 Cloud NAT 閘道。名稱為 swg-autogen-nat,且位於適當的區域和虛擬私有雲網路中。

    3. 按一下 [編輯]

    4. 在「Cloud NAT IP 位址」中,將設定從「自動 (建議)」變更為「手動」

    5. 在「IP addresses」(IP 位址) 的部分,選取您預留的靜態 IP 位址。

      如要新增多個 IP 位址,請按一下「新增 IP 位址」

    6. 按一下 [儲存]

Cloud Shell

  1. 指定專案和區域詳細資料。

    gcloud config set project PROJECT_ID
    gcloud config set compute/region REGION
    

    更改下列內容:

    • PROJECT_ID:您的 Google Cloud 專案 ID
    • REGION:部署 Secure Web Proxy 執行個體的區域
  2. 預留靜態外部 IP 位址。

    gcloud compute addresses create swp-nat-ip-1 \
        --region=REGION
    gcloud compute addresses create swp-nat-ip-2 \
        --region=REGION
    # Repeat for more IPs if required.
    
  3. 找出與 Cloud NAT 閘道相關聯的 Cloud Router 名稱。

    gcloud compute routers list \
        --region REGION \
        --filter="network:(NETWORK_NAME) AND name:(swg-autogen-router-*)" \
        --format="get(name)"
    

    更改下列內容:

    • REGION:部署 Cloud Router 的區域,適用於您的安全網路 Proxy 執行個體
    • NETWORK_NAME:虛擬私有雲網路名稱

    輸出結果會與下列內容相似:

    swg-autogen-router-1
    
  4. 列出與該 Cloud Router 相關聯的 Cloud NAT 設定,確認 Cloud NAT 閘道的名稱 (即 swg-autogen-nat)。

    gcloud compute routers nats list \
        --router=swg-autogen-router-1 \
        --region=REGION
    
  5. 更新 Cloud NAT 閘道,改為使用手動 IP 位址。

    gcloud compute routers nats update swg-autogen-nat \
        --router=swg-autogen-router-1 \
        --region=REGION \
        --nat-external-ip-pool=swp-nat-ip-1,swp-nat-ip-2
        # You can list multiple reserved IP names separated by commas.
    

限制

您必須在與相關聯的 Secure Web Proxy 執行個體相同的區域中,部署 Cloud NAT 閘道。這是因為每個 Proxy 都必須在特定區域中擁有相關聯的 Cloud NAT 閘道。

在虛擬私有雲網路區域中佈建第一個 Proxy 時,系統會自動建立 Cloud NAT 閘道。不過,閘道只能為部署在特定區域和虛擬私有雲網路中的 Secure Web Proxy 執行個體提供網際網路存取權。

後續步驟