快速入門導覽課程:使用 Cloud DNS 設定網域名稱的 DNS 記錄

本頁面說明如何為網域名稱設定 Cloud DNS 代管區域及資源記錄,其中提供的範例會引導您建立代管區域,然後設定網域的位址 (A) 和正規名稱 (CNAME) 記錄。


如要直接在 Google Cloud 控制台中,按照這項工作的逐步指南操作,請按一下「Guide me」(逐步引導)

逐步引導


詳情請參閱下列資源:

  • 如要瞭解 Cloud DNS 概念,請參閱「Cloud DNS 總覽」。
  • 如要瞭解 Cloud DNS 相關術語,請參閱「重要詞彙」。
  • 如需虛擬私有雲網路設定資訊,請參閱「VPC 總覽」。
  • 如需設定方式及 API 資訊,請參閱「後續步驟」。

必要條件

本快速入門導覽課程假設您已具備下列條件:

事前準備

  1. 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.
  2. 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

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

  4. Make sure that you have the following role or roles on the project: Service Usage Admin, DNS Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 選取所需專案。
    3. 點按「 Grant access」(授予存取權)
    4. 在「New principals」(新主體) 欄位中,輸入您的使用者 ID。 這通常是指 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下「 Add another role」(新增其他角色),然後新增其他角色。
    7. 按一下「Save」(儲存)
  5. 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

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

  7. Make sure that you have the following role or roles on the project: Service Usage Admin, DNS Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 選取所需專案。
    3. 點按「 Grant access」(授予存取權)
    4. 在「New principals」(新主體) 欄位中,輸入您的使用者 ID。 這通常是指 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下「 Add another role」(新增其他角色),然後新增其他角色。
    7. 按一下「Save」(儲存)
  8. Enable the DNS API.

    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 API

在 Cloud DNS 中建立代管的公開區域

  1. 前往 Google Cloud 控制台的「Create a DNS zone」(建立 DNS 區域) 頁面。

    前往建立 DNS 區域

  2. 如要建立公開 DNS 區域,請按一下「Create zone」(建立區域)

  3. 在「Zone type」(可用區類型) 中選擇「Public」(公開)

  4. 「Zone name」(可用區名稱) 欄位中輸入 my-new-zone

  5. 「DNS name」(DNS 名稱) 欄位中輸入您購買的網域名稱。您只需要輸入網域名稱,例如:

    example.com
    
  6. 「DNSSEC」下拉式清單中選取「Off」(停用)

  7. 按一下「Create」(建立)

隨即會顯示「Zone details」(區域詳細資料) 頁面,系統已為您建立預設的 NS 和 SOA 記錄。

如要編輯記錄,請在「Zone details」(區域詳細資料) 頁面中,找出要編輯的記錄,然後按一下資料列尾端的「Edit」(編輯)

建立記錄以將網域指向外部 IP 位址

如果 IP 位址的格式為 #.#.#.#,則使用的是 IPv4 位址,必須建立 A 記錄。

如果 IP 位址的格式為 #:#:#:#:#:#:#:#,則使用的是 IPv6 位址,必須建立 AAAA 記錄。

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

    前往 Cloud DNS

  2. 按一下要新增記錄集的區域。

  3. 點選「Add Standard」(新增標準)

  4. 在「Resource Record Type」(資源記錄類型) 部分,選取 A 即可建立 A 記錄。如要建立 AAAA 記錄,請選取 AAAA

  5. 在「IPv4 Address」(IPv4 位址) 或「IPv6 Address」(IPv6 位址) 部分,輸入要與這個網域搭配使用的 IP 位址。

  6. 點選「Create」(建立)

建立 www 子網域的 CNAME 記錄

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

    前往 Cloud DNS

  2. 按一下要新增記錄集的區域。

  3. 點選「Add Standard」(新增標準)

  4. 在「DNS Name」(DNS 名稱) 中輸入 www

  5. 在「Resource Record Type」(資源記錄類型) 部分,選取「CNAME」。

  6. 在「Canonical name」(正規名稱) 中輸入網域名稱,後面加上半形句號 (例如 example.com.)。

  7. 點選「Create」(建立)

記錄更新需要一段時間才會生效,實際的時間長度取決於記錄的存留時間 (TTL) 值。如要驗證 DNS 記錄是否正常運作,請造訪該網域名稱,並確認網域是否解析為您的 IP 位址。

更新網域名稱伺服器以發布網域

最後,您必須更新網域名稱伺服器才能使用 Cloud DNS,以將新記錄發布至網際網路。

您已成功使用 Cloud DNS 設定 DNS 記錄。

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。

  1. 前往 Google Cloud 控制台的「Cloud DNS zones」(Cloud DNS 區域) 頁面。

    前往 Cloud DNS 區域

  2. 按一下區域名稱 (my-new-zone) 前往「Zone details」(區域詳細資料) 頁面。

  3. 選取您建立的 A 和 CNAME 記錄。

  4. 按一下「Delete record sets」(刪除記錄集)

  5. 前往「Cloud DNS zones」(Cloud DNS 區域) 頁面。

    前往 Cloud DNS 區域

  6. 如要刪除區域,請勾選 my-new-zone 核取方塊,然後按一下資料列尾端的「Delete zone」(刪除區域)

後續步驟