0
0
GCPcloud~5 mins

Cloud DNS for domain management in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing your website's address on the internet can be tricky. Cloud DNS helps you connect your domain name to your website's server easily and reliably.
When you want to point your domain name to a website hosted on Google Cloud.
When you need to create custom DNS records like A, CNAME, or MX for your domain.
When you want to manage your domain's DNS settings without using your domain registrar's interface.
When you want fast and reliable DNS resolution for your domain.
When you want to automate DNS changes using command-line tools.
Config File - dns-zone.yaml
dns-zone.yaml
apiVersion: dns.cnrm.cloud.google.com/v1beta1
kind: DNSManagedZone
metadata:
  name: example-zone
spec:
  dnsName: example.com.
  description: "Managed zone for example.com"
  visibility: public

This file defines a managed DNS zone named example-zone for the domain example.com. The dnsName is the domain you want to manage. visibility: public means the DNS zone is accessible on the internet.

Commands
This command creates a new DNS managed zone named 'example-zone' for the domain 'example.com'. It sets up the zone so you can add DNS records to it.
Terminal
gcloud dns managed-zones create example-zone --dns-name=example.com. --description="Managed zone for example.com"
Expected OutputExpected
Created [https://dns.googleapis.com/dns/v1/projects/my-project/managedZones/example-zone].
--dns-name - Specifies the domain name for the DNS zone.
--description - Adds a description to help identify the zone.
Starts a new transaction to add or change DNS records in the 'example-zone'. Transactions help group changes safely.
Terminal
gcloud dns record-sets transaction start --zone=example-zone
Expected OutputExpected
Transaction started for managed-zone [example-zone].
--zone - Specifies which DNS zone to work with.
Adds an A record pointing 'www.example.com' to the IP address 1.2.3.4 with a time-to-live of 300 seconds in the current transaction.
Terminal
gcloud dns record-sets transaction add --name=www.example.com. --ttl=300 --type=A 1.2.3.4 --zone=example-zone
Expected OutputExpected
Record addition appended to transaction for managed-zone [example-zone].
--name - Specifies the DNS name for the record.
--ttl - Sets how long DNS servers cache this record.
--type - Specifies the DNS record type.
--zone - Specifies the DNS zone.
Applies all the changes made in the current transaction to the DNS zone, making the new records live.
Terminal
gcloud dns record-sets transaction execute --zone=example-zone
Expected OutputExpected
Executed transaction for managed-zone [example-zone].
--zone - Specifies which DNS zone to update.
Lists all DNS records in the 'example-zone' so you can verify your changes.
Terminal
gcloud dns record-sets list --zone=example-zone
Expected OutputExpected
NAME TYPE TTL DATA www.example.com. A 300 1.2.3.4 example.com. NS 21600 ns-cloud-e1.googledomains.com. example.com. NS 21600 ns-cloud-e2.googledomains.com. example.com. NS 21600 ns-cloud-e3.googledomains.com. example.com. NS 21600 ns-cloud-e4.googledomains.com.
--zone - Specifies the DNS zone to list records from.
Key Concept

If you remember nothing else from this pattern, remember: Cloud DNS lets you control your domain's address records easily and safely using managed zones and transactions.

Common Mistakes
Forgetting the trailing dot at the end of domain names in commands.
Without the trailing dot, the domain name is treated as relative and may cause incorrect DNS entries.
Always include a trailing dot at the end of domain names, like 'example.com.'.
Trying to add DNS records without starting a transaction first.
DNS record changes require a transaction to group changes; skipping this causes errors.
Always start a transaction with 'gcloud dns record-sets transaction start' before adding or removing records.
Not executing the transaction after adding records.
Changes are only saved and applied after executing the transaction; otherwise, they remain pending.
Run 'gcloud dns record-sets transaction execute' to apply your DNS changes.
Summary
Create a managed DNS zone to control your domain's DNS records.
Use transactions to safely add or change DNS records like A or CNAME.
List DNS records to verify your changes are applied correctly.