設定全域網路防火牆政策,拒絕連往特定地理位置的輸出連線

本教學課程說明如何建立及設定全域網路防火牆政策,封鎖網路中特定地理位置的外送流量。 本教學課程會逐步說明如何建立含有兩個子網路的虛擬私有雲 (VPC) 網路、設定含有地理位置防火牆規則的防火牆政策,然後測試防火牆規則。

目標

本教學課程將說明如何完成下列工作:

  • 建立自訂虛擬私有雲網路,其中包含不同區域的兩個子網路。
  • 在下列每個區域中建立虛擬機器 (VM) 執行個體:美國和新加坡。
  • 建立 Cloud Router 和 Cloud NAT 閘道,允許美國 VM 存取公開網際網路。
  • 建立全域網路防火牆政策,並新增防火牆規則,以啟用 Identity-Aware Proxy (IAP)。
  • 在新加坡 VM 上安裝 Apache 伺服器。
  • 新增防火牆規則,封鎖特定地理位置的流量。
  • 測試地理位置防火牆規則。

下圖顯示自訂虛擬私有雲網路中,us-central1asia-southeast1 區域內 VM 之間的流量。全域網路防火牆政策會封鎖傳送至特定地理位置的輸出流量。us-central1 區域中的 VM 使用 Cloud Router 和 Cloud NAT 存取網際網路,而不使用外部 IP 位址。us-central1 區域中的 VM 會使用 asia-southeast1 區域中 VM 的外部 IP 位址,測試防火牆規則。

全域網路防火牆政策會封鎖從子網路到特定地理位置的輸出流量。
全域網路防火牆政策會禁止子網路將輸出流量傳送至特定地理位置 (按一下可放大)。

事前準備

  • Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  • In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  • Verify that billing is enabled for your Google Cloud project.

  • In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  • Verify that billing is enabled for your Google Cloud project.

  • 確認您具備 Compute 網路管理員角色 (roles/compute.networkAdmin)。
  • Enable the Compute Engine and Identity-Aware Proxy (IAP) APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  • 如果您希望透過指令列操作,請先安裝 Google Cloud CLI。如需該工具的概念與安裝資訊,請參閱 gcloud CLI 總覽

    注意:如果您先前沒有執行過 Google Cloud CLI,請執行 gcloud init 指令,初始化 gcloud CLI 目錄。

建立含子網路的自訂虛擬私有雲網路

建立含有兩個 IPv4 子網路的自訂模式虛擬私有雲網路。

控制台

  1. 前往 Google Cloud 控制台的「VPC Networks」(虛擬私有雲網路) 頁面。

    前往「VPC networks」(虛擬私有雲網路)

  2. 按一下「建立虛擬私有雲網路」

  3. 在「Name」(名稱) 中輸入 vpc-geo-location

  4. 在「子網路建立模式」部分,選取「自訂」

  5. 在「New subnet」(新子網路) 部分,指定子網路的以下設定參數:

    • Name (名稱):subnet-1-us
    • Region (區域):us-central1
    • IPv4 範圍10.0.0.0/24
  6. 按一下 [完成]

  7. 按一下「Add subnet」(新增子網路),然後指定下列設定參數:

    • Name (名稱):subnet-2-sg
    • Region (區域):asia-southeast1
    • IPv4 範圍192.168.200.0/24
  8. 按一下 [完成]

  9. 點選「建立」

gcloud

  1. 如要開啟終端機,請按一下「啟用 Cloud Shell」
  2. 如要建立 VPC 網路,請執行下列指令:

    gcloud compute networks create vpc-geo-location \
      --subnet-mode=custom
    
  3. 在「授權 Cloud Shell」對話方塊中,按一下「授權」

  4. 如要建立子網路,請執行下列指令:

    gcloud compute networks subnets create subnet-1-us \
      --network=vpc-geo-location \
      --region=us-central1 \
      --range=10.0.0.0/24
    
  5. 如要建立另一個子網路,請執行下列指令:

    gcloud compute networks subnets create subnet-2-sg \
      --network=vpc-geo-location \
      --region=asia-southeast1 \
      --range=192.168.200.0/24
    

建立 VM

在本節中,您會在上一節設定的子網路中建立兩個 VM。

us-central1 區域中建立 VM

us-central1 區域中建立沒有外部 IP 位址的 VM。

控制台

如要在 us-central1 區域中建立 VM,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。

    前往「建立執行個體」

  2. 在「機器設定」窗格中,執行下列操作:

    1. 在「Name」(名稱) 中輸入 instance-1-us
    2. 在「Region」(區域) 中選取 us-central1 (Iowa)
  3. 在導覽選單中,按一下「Networking」(網路)

    1. 在「Network interfaces」(網路介面) 部分,按一下 default,然後指定下列設定參數:
      • 「Network」(網路)vpc-geo-location
      • 「Subnetwork」(子網路)subnet-1-us IPv4 (10.0.0.0/24)
      • 外部 IPv4 位址
    2. 按一下 [完成]
  4. 點選「建立」

gcloud

如要在 us-central1 區域中建立 VM,請執行下列指令:

gcloud compute instances create instance-1-us \
     --network=vpc-geo-location \
     --zone=us-central1-a \
     --stack-type=IPV4_ONLY \
     --no-address \
     --subnet=subnet-1-us

asia-southeast1 區域中建立 VM

控制台

如要在 asia-southeast1 區域中建立 VM,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。

    前往「建立執行個體」

  2. 在「機器設定」窗格中,執行下列操作:

    1. 在「Name」(名稱) 中輸入 instance-2-sg
    2. 在「區域」部分,選取「asia-southeast1 (Singapore)」。
  3. 在導覽選單中,按一下「Networking」(網路)

    1. 在「Network interfaces」(網路介面) 部分,按一下 default,然後指定下列設定參數:
      • 「Network」(網路)vpc-geo-location
      • 「Subnetwork」(子網路)subnet-2-sg IPv4 (192.168.200.0/24)
      • 外部 IPv4 位址
    2. 按一下 [完成]
  4. 點選「建立」

gcloud

如要在 asia-southeast1 區域中建立 VM,請執行下列指令:

gcloud compute instances create instance-2-sg \
    --network=vpc-geo-location \
    --zone=asia-southeast1-b \
    --subnet=subnet-2-sg \
    --stack-type=IPV4_ONLY

建立 Cloud Router 和 Cloud NAT 閘道

在上一節中,您建立了兩個 VM,分別是 instance-1-usasia-southeast1。如要允許 instance-1-us VM 存取公用網際網路,請建立 Cloud Router 和 Cloud NAT 閘道。

控制台

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

    前往 Cloud NAT

  2. 按一下「開始使用」或「建立 Cloud NAT 閘道」

  3. 在「閘道名稱」中輸入 nat-gateway

  4. 在「NAT type」(NAT 類型) 中,選取「Public」(公開)

  5. 在「Select Cloud Router」部分,指定下列設定參數:

    • 「Network」(網路)vpc-geo-location
    • 區域us-central1
    • Cloud Router建立新的路由器
      1. 在「Name」(名稱) 中輸入 router-fw-rules
      2. 點選「建立」
  6. 點選「建立」

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

    前往「IP addresses」(IP 位址)

  8. 按一下「External IP Addresses」(外部 IP 位址) 分頁標籤,然後複製 Cloud NAT 的 IP 位址 (nat-auto-ip)。驗證 instance-1-us VM 與 instance-2-sg VM 之間的連線時,會使用這個 IP 位址。

gcloud

  1. 如要建立 Cloud Router,請執行下列指令:

    gcloud compute routers create router-fw-rules \
      --network=vpc-geo-location \
      --region=us-central1
    
  2. 如要建立 Cloud NAT 閘道,請執行下列指令:

    gcloud compute routers nats create nat-gateway \
      --router=router-fw-rules \
      --region=us-central1 \
      --auto-allocate-nat-external-ips \
      --nat-all-subnet-ip-ranges
    
  3. 如要查看 Cloud NAT IP 位址,請執行下列指令:

    gcloud compute routers get-nat-ip-info \
      router-fw-rules \
      --region=us-central1
    

    請務必複製 Cloud NAT 的 IP 位址 (natIp)。驗證 instance-1-us VM 和 instance-2-sg VM 之間的連線時,會使用這個 IP 位址。

建立全域網路防火牆政策,啟用 IAP

在本節中,您將建立全域網路防火牆政策,並新增防火牆規則來啟用 IAP。IAP 可讓您管理 VM 執行個體的存取權。

防火牆規則具有下列特性。

  • 來自 IP 範圍 35.235.240.0/20 的輸入流量。這個範圍包含 IAP 用於 TCP 轉送的所有 IP 位址。
  • 連線至您希望透過 IAP TCP 轉送功能存取的所有通訊埠,例如適用於 SSH 的通訊埠「22」。

控制台

如要允許透過 IAP 存取 vpc-geo-location 網路中的所有 VM 執行個體,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Firewall policies」(防火牆政策) 頁面。

    前往「Firewall policies」(防火牆政策)

  2. 按一下「建立防火牆政策」

  3. 在「設定政策」部分,於「政策名稱」輸入 fw-policy

  4. 在「部署範圍」部分選取「全域」,然後按一下「繼續」

  5. 如要為政策建立規則,請在「新增規則」部分中,按一下「新增規則」

    1. 在「Priority」(優先順序) 中輸入 100
    2. 在「Direction of traffic」(流量方向) 中選取 [Ingress] (輸入)
    3. 在「Action on match」(相符時執行的動作) 中選取 [Allow] (允許)
    4. 將「記錄」設為「開啟」
    5. 在「目標」部分中,針對「目標類型」選取「網路中的所有執行個體」
    6. 在「來源」部分中,於「IP 範圍」輸入 35.235.240.0/20
    7. 在「通訊協定和通訊埠」部分,選取「指定的通訊協定和通訊埠」
    8. 勾選「TCP」核取方塊,然後在「Ports」(通訊埠) 輸入 22
    9. 點選「建立」
  6. 按一下「繼續」

  7. 如要將虛擬私有雲網路與政策建立關聯,請在「將政策與虛擬私有雲網路建立關聯」部分中,按一下「建立關聯」

  8. 勾選 vpc-geo-location 核取方塊,然後按一下「關聯」

  9. 按一下「繼續」

  10. 點選「建立」

gcloud

如要允許 IAP 存取 vpc-geo-location 網路中的所有 VM 執行個體,請執行下列指令:

  1. 如要建立防火牆政策,請執行下列指令:

    gcloud compute network-firewall-policies create fw-policy \
        --global
    
  2. 如要建立防火牆規則,允許流量前往所有目的地並啟用記錄,請執行下列指令:

    gcloud compute network-firewall-policies rules create 100 \
        --firewall-policy=fw-policy \
        --direction=INGRESS \
        --action=ALLOW \
        --layer4-configs=tcp:22 \
        --src-ip-ranges=35.235.240.0/20 \
        --global-firewall-policy \
        --enable-logging
    
    
  3. 如要將防火牆政策與虛擬私有雲網路建立關聯,請執行下列指令:

    gcloud compute network-firewall-policies associations create \
        --firewall-policy=fw-policy \
        --network=vpc-geo-location \
        --name=pol-association-fw-rules \
        --global-firewall-policy
    

建立防火牆規則

在本節中,您將建立防火牆規則,允許 instance-2-sg VM 上的連入連線。

控制台

  1. 前往 Google Cloud 控制台的「Firewall policies」(防火牆政策) 頁面。

    前往「Firewall policies」(防火牆政策)

  2. 在「網路防火牆政策」部分,按一下 fw-policy

  3. 按一下「建立規則」

  4. 在「Priority」(優先順序) 中輸入 500

  5. 在「Direction of traffic」(流量方向) 中選取 [Ingress] (輸入)

  6. 在「Action on match」(相符時執行的動作) 中選取 [Allow] (允許)

  7. 將「記錄」設為「開啟」

  8. 在「目標」部分中,針對「目標類型」選取「網路中的所有執行個體」

  9. 在「來源」部分中,為「IP 範圍」輸入 NAT_IP_ADDRESS

    NAT_IP_ADDRESS 替換為指派給 Cloud NAT 的 IP 位址。詳情請參閱「建立 Cloud Router 和 Cloud NAT 閘道」。

  10. 點選「建立」

gcloud

如要更新防火牆政策,請執行下列指令:

gcloud compute network-firewall-policies rules create 500 \
    --firewall-policy=fw-policy \
    --direction=INGRESS \
    --action=ALLOW \
    --src-ip-ranges=NAT_IP_ADDRESS \
    --layer4-configs=all \
    --global-firewall-policy \
    --enable-logging

NAT_IP_ADDRESS 替換為指派給 Cloud NAT 的 IP 位址。詳情請參閱「建立 Cloud Router 和 Cloud NAT 閘道」。

安裝 Apache 伺服器

在本節中,您會在 instance-2-sg VM 上安裝 Apache 伺服器。

控制台

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. instance-2-sg VM 的「連線」欄中,按一下「SSH」

  3. 在「SSH-in-browser」(直接透過瀏覽器進行 SSH 連線) 對話方塊中,按一下「Authorize」(授權),然後等待連線建立。

  4. 如要更新執行個體上的套件清單,請執行下列指令:

    sudo apt-get update
    

    程序完成後,系統會產生以下訊息:

    Reading package lists... Done.

  5. 如要安裝 apache2 HTTP Server 套件,請在命令提示字元中執行下列指令:

    sudo apt-get install apache2 php7.0
    

    程序進行期間,系統會產生下列訊息:

    After this operation, 56.0 MB of additional disk space will be used. Do you want to continue? [Y/n]

    按下 Y 鍵確認,然後按下 Enter 鍵。

  6. 如要覆寫 Apache 網路伺服器預設網頁,請執行下列指令:

    echo '<!doctype html><html><body><h1>Hello World!</h1></body></html>' | sudo tee /var/www/html/index.html
    
  7. 關閉「SSH-in-browser」(透過瀏覽器進行 SSH 連線) 對話方塊。

gcloud

  1. 如要使用 SSH 連線至 instance-2-sg VM,請執行下列指令:

    gcloud compute ssh instance-2-sg \
        --zone=asia-southeast1-b \
        --tunnel-through-iap
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

  2. 如要更新執行個體上的套件清單,請執行下列指令:

    sudo apt-get update
    

    程序完成後,系統會產生以下訊息:

    Reading package lists... Done.

  3. 如要安裝 apache2 HTTP Server 套件,請在命令提示字元中執行下列指令:

    sudo apt-get install apache2 php7.0
    

    程序進行期間,系統會產生下列訊息:

    After this operation, 56.0 MB of additional disk space will be used. Do you want to continue? [Y/n]

    按下 Y 鍵確認,然後按下 Enter 鍵。

  4. 如要覆寫 Apache 網路伺服器預設網頁,請執行下列指令:

    echo '<!doctype html><html><body><h1>Hello World!</h1></body></html>' | sudo tee /var/www/html/index.html
    
  5. 如要關閉「透過瀏覽器建立 SSH 連線」,請輸入 exit

驗證連線

instance-2-sg VM 上安裝 Apache 伺服器後,請使用 instance-2-sg VM 的外部 IP 位址,從 instance-2-sg VM 連線至 instance-1-us VM。

控制台

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. instance-2-sg VM 的「External IP」(外部 IP) 欄中,複製 VM 的外部 IP 位址。

  3. instance-1-us VM 的「連線」欄中,按一下「SSH」

  4. 在「SSH-in-browser」(直接透過瀏覽器進行 SSH 連線) 對話方塊中,按一下「Authorize」(授權),然後等待連線建立。

  5. 如要驗證連線,請執行下列指令:

    curl EXTERNAL_IP -m 2
    

    EXTERNAL_IP 替換為 instance-2-sg VM 的 IP 位址。

    預期的回應訊息如下:

    <!doctype html><html><body><h1>Hello World!</h1></body></html>

  6. 關閉「SSH-in-browser」(透過瀏覽器進行 SSH 連線) 對話方塊。

gcloud

  1. 如要查看 instance-2-sg VM 的外部 IP 位址,請執行下列指令:

    gcloud compute instances describe instance-2-sg \
        --zone=asia-southeast1-b \
        --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。 請務必記下 instance-2-sg VM 的外部 IP 位址。

  2. 如要使用 SSH 連線至 instance-1-us VM,請執行下列指令:

    gcloud compute ssh instance-1-us \
        --zone=us-central1-a \
        --tunnel-through-iap
    
  3. 如要驗證連線,請執行下列指令:

      curl EXTERNAL_IP -m 2
    

    EXTERNAL_IP 替換為 instance-2-sg VM 的 IP 位址。

    預期的回應訊息如下:

    <!doctype html><html><body><h1>Hello World!</h1></body></html>

  4. 如要關閉「透過瀏覽器建立 SSH 連線」,請輸入 exit

新增防火牆規則,封鎖特定地理位置的流量

在本節中,您將為虛擬私有雲新增防火牆規則,vpc-geo-location 封鎖前往義大利、波蘭和新加坡的輸出流量。

控制台

如要在「建立全域網路防火牆政策」一節中建立的 fw-policy 中新增規則,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Firewall policies」(防火牆政策) 頁面。

    前往「Firewall policies」(防火牆政策)

  2. 在「網路防火牆政策」部分,按一下 fw-policy

  3. 按一下「建立規則」

  4. 在「Priority」(優先順序) 中輸入 200

  5. 在「Direction of traffic」(流量方向) 中選取「Egress」(輸出)

  6. 在「Action on match」(相符時執行的動作) 中選取「Deny」(拒絕)

  7. 將「記錄」設為「開啟」

  8. 在「目的地」部分,選取「地理位置」新加坡 (SG)波蘭 (PL)義大利 (IT)

  9. 按一下 [確定]

  10. 點選「建立」

gcloud

如要在「建立全域網路防火牆政策」一節中建立的 fw-policy 中新增規則,請執行下列指令:

gcloud compute network-firewall-policies rules create 200 \
    --firewall-policy=fw-policy \
    --direction=EGRESS \
    --action=DENY \
    --dest-region-codes=SG,PL,IT \
    --layer4-configs=all \
    --global-firewall-policy \
    --enable-logging

測試地理位置防火牆規則

控制台

將規則新增完畢,封鎖前往新加坡 (SG)、波蘭 (PL) 和義大利 (IT) 的輸出流量後,請按照下列步驟測試規則:

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. instance-2-sg VM 的「External IP」(外部 IP) 欄中,複製 VM 的外部 IP 位址。

  3. instance-1-us VM 的「連線」欄中,按一下「SSH」

  4. 在「SSH-in-browser」(直接透過瀏覽器進行 SSH 連線) 對話方塊中,按一下「Authorize」(授權),然後等待連線建立。

  5. 如要確認傳送至 instance-2-sg VM 的輸出流量遭到封鎖,請執行下列指令:

    curl EXTERNAL_IP -m 2
    

    EXTERNAL_IP 替換為 instance-2-sg VM 的 IP 位址。

    由於您已建立防火牆規則,拒絕從美國 VM 傳送外部流量至新加坡 VM,因此系統會顯示 Connection timed out 訊息。

  6. 如要確認前往波蘭的輸出流量已遭封鎖,請執行下列指令:

      curl  `https://www.gov.pl` -m 2
    

    您已建立防火牆規則,拒絕外部流量連往波蘭網站,因此系統會顯示 Connection timed out 訊息。

  7. 如要確認前往義大利的出站流量已遭封鎖,請執行下列指令:

      curl  `https://www.esteri.it/it/` -m 2
    

    由於您建立防火牆規則,拒絕外部流量連往義大利網站,因此出現 Connection timed out 訊息是預期行為。

  8. 關閉「SSH-in-browser」(透過瀏覽器進行 SSH 連線) 對話方塊。

gcloud

新增規則來封鎖前往新加坡 (SG)、波蘭 (PL) 和義大利 (IT) 的輸出流量後,請執行下列指令來測試規則:

  1. 如要查看 instance-2-sg VM 的外部 IP 位址,請執行下列指令:

    gcloud compute instances describe instance-2-sg \
       --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。請務必記下 instance-2-sg VM 的外部 IP 位址。

  2. 如要使用 SSH 連線至 instance-1-us VM,請執行下列指令:

    gcloud compute ssh instance-1-us \
       --zone=us-central1-a \
       --tunnel-through-iap
    
  3. 如要確認前往新加坡的輸出流量已遭封鎖,請執行下列指令:

    curl EXTERNAL_IP -m 2
    

    EXTERNAL_IP 替換為 instance-2-sg VM 的 IP 位址。

    由於您已建立防火牆規則,拒絕從美國 VM 傳送外部流量至新加坡 VM,因此系統會顯示 Connection timed out 訊息。

  4. 如要確認前往波蘭的輸出流量已遭封鎖,請執行下列指令:

    curl https://www.gov.pl -m 2
    

    您建立的防火牆規則會拒絕來自波蘭網站的外部流量,因此出現 Connection timed out 訊息是正常情況。

  5. 如要確認前往義大利的出站流量已遭封鎖,請執行下列指令:

    curl  https://www.esteri.it/it/ -m 2
    

    由於您建立的防火牆規則會拒絕傳送至義大利網站的外部流量,因此系統會顯示 Connection timed out 訊息。

  6. 如要關閉「透過瀏覽器建立 SSH 連線」對話方塊,請輸入 exit

查看記錄

您可以存取記錄,確認防火牆規則是否已套用至輸出流量。如要查看記錄詳細資料,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Firewall policies」(防火牆政策) 頁面。

    前往「Firewall policies」(防火牆政策)

  2. 在「網路防火牆政策」部分,按一下 fw-policy 名稱。

  3. 按一下「資料欄顯示選項」

  4. 在「顯示的資料欄」對話方塊中,選取「命中次數」,然後按一下「確定」

  5. 在「命中次數」欄中,選取您在「建立全域網路防火牆政策」期間建立的規則編號。 「Logs Explorer」頁面隨即開啟。

  6. 如要查看套用至輸出流量的防火牆規則,請展開個別記錄。您可以查看連線、處置和遠端位置詳細資料。

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取本教學課程所用資源的費用,請刪除含有相關資源的專案,或者保留專案但刪除個別資源。

在本節中,您將刪除在本教學課程中建立的資源。

刪除防火牆政策

控制台

  1. 前往 Google Cloud 控制台的「Firewall policies」(防火牆政策) 頁面。

    前往「Firewall policies」(防火牆政策)

  2. 在「網路防火牆政策」部分,按一下 fw-policy 名稱。

  3. 按一下「關聯項目」分頁標籤。

  4. 勾選 vpc-geo-location 核取方塊,然後按一下「移除關聯」

  5. 在「Remove a firewall policy association」(移除防火牆政策連結關係) 對話方塊中,按一下「Remove」(移除)

  6. 按一下「fw-policy」標題旁邊的「刪除」

  7. 在「刪除防火牆政策」對話方塊中,按一下「刪除」

gcloud

  1. 移除防火牆政策與 VPC 網路之間的關聯。

    gcloud compute network-firewall-policies associations delete \
      --name=pol-association-fw-rules \
      --firewall-policy=fw-policy \
      --global-firewall-policy
    
    The network firewall policy does not have an association with pol-association-fw-rules. Google Cloud
  2. 刪除防火牆政策。

    gcloud compute network-firewall-policies delete fw-policy \
        --global
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

刪除 VM

控制台

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. 勾選 instance-1-usinstance-2-sg VM 的核取方塊。

  3. 按一下「Delete」(刪除)

  4. 在「Delete 2 instances?」(要刪除 2 個執行個體嗎?) 對話方塊中,按一下「Delete」(刪除)

gcloud

  1. 如要刪除 instance-1-us VM,請執行下列指令:

    gcloud compute instances delete instance-1-us \
        --zone=us-central1-a
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

  2. 如要刪除 instance-2-sg VM,請執行下列指令:

    gcloud compute instances delete instance-2-sg \
        --zone=asia-southeast1-b
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

刪除 Cloud NAT 閘道和 Cloud Router

控制台

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

    前往 Cloud Router

  2. 勾選「router-fw-rules核取方塊。

  3. 按一下「Delete」(刪除)

  4. 在「Delete router-fw-rules」(刪除路由器防火牆規則) 對話方塊中,按一下「Delete」(刪除)

刪除 Cloud Router 時,相關聯的 Cloud NAT 閘道也會一併刪除。

gcloud

如要刪除 router-fw-rules Cloud Router,請執行下列指令:

gcloud compute routers delete router-fw-rules \
    --region=us-central1

系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

刪除 Cloud Router 時,相關聯的 Cloud NAT 閘道也會一併刪除。

刪除虛擬私有雲網路及其子網路

控制台

  1. 前往 Google Cloud 控制台的「VPC Networks」(虛擬私有雲網路) 頁面。

    前往「VPC networks」(虛擬私有雲網路)

  2. 在「Name」(名稱) 欄中,按一下 vpc-geo-location

  3. 按一下「刪除虛擬私有雲網路」

  4. 在「刪除網路」對話方塊中,按一下「刪除」

刪除 VPC 時,子網路也會一併刪除。

gcloud

  1. 如要刪除 vpc-geo-location 虛擬私有雲網路的子網路 subnet-1-us,請執行下列指令:

    gcloud compute networks subnets delete subnet-1-us \
        --region=us-central1
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

  2. 如要刪除 vpc-geo-location 虛擬私有雲網路的子網路 subnet-2-sg,請執行下列指令:

    gcloud compute networks subnets delete subnet-2-sg \
        --region=asia-southeast1
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

  3. 如要刪除 vpc-geo-location VPC 網路,請執行下列指令:

    gcloud compute networks delete vpc-geo-location
    

    系統提示時,請按下 Y 確認,然後按下 Enter 鍵。

後續步驟