快速入門導覽課程:使用 Cloud DNS 設定網域名稱的 DNS 記錄
本頁面說明如何為您的網域名稱設定 Cloud DNS 代管區域及資源記錄,其中提供的範例將說明如何建立代管區域,然後設定網域的位址 (A) 和正式名稱 (CNAME) 記錄。
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
詳情請參閱下列資源:
- 如需 Cloud DNS 概念,請參閱 Cloud DNS 總覽。
- 如需 Cloud DNS 相關術語,請參閱重要術語。
- 如需虛擬私有雲 (VPC) 網路設定資訊,請參閱虛擬私有雲總覽。
- 如需設定方式及 API 資訊,請參閱後續步驟。
需求條件
本快速入門導覽課程假設您已具備下列條件:
- 網域名稱註冊商提供的網域名稱。您可以透過 Cloud Domains 或選擇其他網域註冊商來註冊網域名稱。您可以使用 Cloud Domains API 管理網域。
- Windows Server 虛擬機器 (VM) 執行個體或 Linux VM 執行個體。
- 指向區域 A記錄的 IP 位址。有效的 IP 位址可以是您已執行且具備您可以指向的 IP 位址的伺服器。舉例來說,您可以按照「執行基本 Apache 網路伺服器」教學課程的逐步指引,在 Compute Engine VM 上啟動網路伺服器。
事前準備
- 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
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
    
        Make sure that you have the following role or roles on the project: Service Usage Admin, DNS Administrator Check for the roles- 
              In the Google Cloud console, go to the IAM page. Go to IAM
- Select the project.
- 
              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. 
- 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- 
              In the Google Cloud console, go to the IAM page. 前往 IAM
- 選取專案。
- 按一下 「授予存取權」。
- 
              在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。 
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
 
- 
              
- 
    
    
      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
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
    
        Make sure that you have the following role or roles on the project: Service Usage Admin, DNS Administrator Check for the roles- 
              In the Google Cloud console, go to the IAM page. Go to IAM
- Select the project.
- 
              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. 
- 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- 
              In the Google Cloud console, go to the IAM page. 前往 IAM
- 選取專案。
- 按一下 「授予存取權」。
- 
              在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。 
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
 
- 
              
- 
  
  
    
      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 theserviceusage.services.enablepermission. Learn how to grant roles.
在 Cloud DNS 中建立代管的公開可用區
- 前往 Google Cloud 控制台的「建立 DNS 區域」頁面。 
- 如要建立公開 DNS 可用區,請按一下 - 「Create zone」(建立可用區) 。
- 在「Zone type」(可用區類型) 中選擇「Public」(公開)。 
- 在 - 「Zone name」(可用區名稱) 欄位中輸入- my-new-zone。
- 在 - 「DNS name」(DNS 名稱) 欄位中輸入您購買的網域名稱。您只需要輸入網域名稱,例如:- example.com
- 在 - 「DNSSEC」 下拉式清單中選取「Off」(停用)。
- 按一下 - 「Create」(建立) 。
如要編輯記錄,請在「區域詳細資料」頁面中,找出要編輯的記錄,然後按一下該列末端的「編輯」edit。
建立記錄,將網域指向外部 IP 位址
如果 IP 位址的格式為 #.#.#.#,則您使用的是 IPv4 位址,必須建立 A 記錄。
如果 IP 位址的格式為 #:#:#:#:#:#:#:#,則您使用的是 IPv6 位址,必須建立 AAAA 記錄。
- 前往 Google Cloud 控制台的「Cloud DNS」頁面。 
- 按一下您要新增記錄集的區域。 
- 按一下「新增標準」。 
- 在「Resource Record Type」(資源記錄類型) 部分,選取 - A即可建立- A記錄。如要建立- AAAA記錄,請選取- AAAA。
- 在「IPv4 Address」(IPv4 位址) 或「IPv6 Address」(IPv6 位址) 欄位中,輸入要與這個網域搭配使用的 IP 位址。 
- 點選「建立」。 
為 www 子網域建立 CNAME 記錄
- 前往 Google Cloud 控制台的「Cloud DNS」頁面。 
- 按一下您要新增記錄集的區域。 
- 按一下「新增標準」。 
- 在「DNS Name」(DNS 名稱) 中,輸入 - www
- 在「Resource Record Type」(資源記錄類型) 部分選取 - CNAME。
- 在「Canonical name」(正規名稱) 中輸入網域名稱,後面加上半形句號 (例如 - example.com.)。
- 點選「建立」。 
記錄更新需要一些時間才能傳播完畢,實際的時間長度取決於記錄的存留時間 (TTL) 值。如要驗證 DNS 記錄是否正常運作,請造訪網域名稱,並確認網域是否解析為您的 IP 位址。
為發布網域而更新網域名稱伺服器
最後,您必須更新網域的名稱伺服器以使用 Cloud DNS,才能將新記錄發布至網際網路。
您已成功使用 Cloud DNS 設定 DNS 記錄。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
- 前往 Google Cloud 控制台的「Cloud DNS 區域」頁面。 
- 按一下區域名稱 ( - my-new-zone) 前往「Zone details」(區域詳細資料) 頁面。
- 選取您建立的 A 和 CNAME 記錄。 
- 按一下「刪除記錄集」。 
- 前往「Cloud DNS 區域」頁面。 
- 如要刪除區域,請選取 - my-new-zone核取方塊,然後按一下資料列尾端的「刪除區域」delete。
後續步驟
- 如要新增、刪除或更新記錄,請參閱「管理記錄」。
- 如要使用代管區域,請參閱「建立、修改及刪除區域」。
- 如要尋找使用 Cloud DNS 時可能遇到的常見問題解決方案,請參閱「疑難排解」。
- 如要參閱 API,請前往 Cloud DNS REST API。
- 如要瞭解費用,請參閱 Cloud DNS 定價。