Cloud DNS
Deploying and managing Google Cloud DNS for domain and DNS hosting
Google Cloud DNS is a high-performance, resilient, global Domain Name System (DNS) service that publishes your domain names to the global DNS in a cost-effective way. Cloud DNS translates requests for domain names like "www.example.com" into IP addresses like "192.0.2.1".
Key Features
Global Anycast: Global network of anycast name servers for low-latency DNS resolution
High Availability: 100% uptime SLA with automatic failover
Scalability: Handle millions of DNS queries
Security: DNSSEC support for zone signing and validation
Public and Private Zones: Support for both public internet domains and private VPC DNS
Managed Service: No need to provision or manage DNS servers
Cloud Integration: Works with other GCP services for automatic DNS record management
Programmatic Management: Full API, gcloud, and Terraform support
Logging: Query logging for auditing and analytics
Flexible Pricing: Pay only for hosted zones and queries
Deploying Cloud DNS with Terraform
Basic Public Zone Configuration
resource "google_dns_managed_zone" "example_zone" {
name = "example-zone"
dns_name = "example.com."
description = "Example public DNS zone"
# Default visibility is "public"
labels = {
environment = "production"
}
}
# Create an A record
resource "google_dns_record_set" "a_record" {
name = "www.example.com."
managed_zone = google_dns_managed_zone.example_zone.name
type = "A"
ttl = 300
rrdatas = ["203.0.113.1"]
}
# Create a CNAME record
resource "google_dns_record_set" "cname_record" {
name = "mail.example.com."
managed_zone = google_dns_managed_zone.example_zone.name
type = "CNAME"
ttl = 300
rrdatas = ["ghs.googlehosted.com."]
}
# Create MX records for email
resource "google_dns_record_set" "mx_record" {
name = "example.com."
managed_zone = google_dns_managed_zone.example_zone.name
type = "MX"
ttl = 3600
rrdatas = [
"1 aspmx.l.google.com.",
"5 alt1.aspmx.l.google.com.",
"5 alt2.aspmx.l.google.com.",
"10 alt3.aspmx.l.google.com.",
"10 alt4.aspmx.l.google.com."
]
}
# Create TXT records for verification and SPF
resource "google_dns_record_set" "txt_record" {
name = "example.com."
managed_zone = google_dns_managed_zone.example_zone.name
type = "TXT"
ttl = 3600
rrdatas = [
"\"v=spf1 include:_spf.google.com ~all\"",
"\"google-site-verification=abcdefghijklmnopqrstuvwxyz\""
]
}
# Output the name servers
output "name_servers" {
description = "Cloud DNS name servers for this zone"
value = google_dns_managed_zone.example_zone.name_servers
}Private DNS Zone Configuration
DNSSEC Configuration
Cloud DNS Peering Configuration
Managing Cloud DNS with gcloud CLI
Creating and Managing DNS Zones
Managing DNS Records
Configuring DNSSEC
Managing DNS Policies
Real-World Example: Multi-VPC DNS Architecture
This example demonstrates a complete multi-VPC DNS setup with private zones, forwarding, and DNS peering:
Architecture Overview
Hub & Spoke VPC network architecture
Central DNS management in Hub VPC
DNS forwarding for on-premises integration
DNS peering to shared services
Service Discovery support
Terraform Implementation
Testing DNS Resolution Script
Best Practices
Zone Design
Use descriptive zone names that reflect their purpose
Follow a consistent naming convention
Keep zone structure flat when possible
Consider separate zones for different environments
Performance and Reliability
Set appropriate TTL values (lower for frequently changing records)
Avoid excessive DNS lookups in application code
Use multi-region deployments for public-facing services
Implement DNS monitoring and alerting
Security
Enable DNSSEC for public zones
Implement strict policies for DNS zone access
Limit who can modify DNS records
Use private zones for internal services
Enable logging for audit purposes
Operational Excellence
Use Infrastructure as Code for all DNS configurations
Document DNS architecture and record management processes
Implement automated testing for DNS resolution
Create runbooks for common DNS operations
Cost Optimization
Clean up unused DNS zones and records
Monitor query volumes for unexpected spikes
Consolidate zones where appropriate
Use Cloud DNS Policies efficiently
Common Issues and Troubleshooting
Resolution Issues
Verify VPC network attachments for private zones
Check that DNS peering is correctly configured
Ensure proper IAM permissions for DNS management
Test resolution from different VPC networks
Check for conflicting or overlapping DNS zones
Propagation Delays
Allow sufficient time for DNS changes to propagate
Check if TTL values are set appropriately
Use DNS monitoring tools to verify propagation
Consider reducing TTL before planned changes
Test from multiple global regions
DNSSEC Problems
Ensure correct DS records are published at the parent zone
Verify DNSSEC key signing key (KSK) and zone signing key (ZSK)
Check for DNSSEC validation errors in logs
Test DNSSEC validation with online tools
Allow time for DNSSEC changes to propagate
Integration with On-Premises DNS
Verify DNS forwarding configuration
Check firewall rules for DNS traffic (port 53)
Test DNS resolution in both directions
Configure conditional forwarding on on-premises DNS servers
Check for subnet overlaps causing routing issues
Further Reading
Last updated