How to Move Google Cloud DNS Entries Between Two Projects
🚀 How to Move Google Cloud DNS Entries Between Two Projects
When managing multiple Google Cloud projects, you may encounter the need to move Cloud DNS records (like A, CNAME, TXT, MX records) from one project to another — typically during migrations, consolidations, or reorganizations.
This blog explains how to safely and effectively move your Google Cloud DNS entries between two projects.
📌 Why DNS Entries Are Project-Specific
Google Cloud DNS zones and records are bound to the project where they are created. There's no direct "move" button. Instead, you’ll need to:
- Export DNS records from the source project
- Create a DNS zone in the destination project
- Import the records into the new zone
- Update domain registrar (if needed)
🔧 Step-by-Step Guide
Step 1: Export DNS Records from the Source Project
Use gcloud
to export all resource records from the DNS zone.
# Set source project
gcloud config set project SOURCE_PROJECT_ID
# Export records to a file
gcloud dns record-sets export exported-dns.yaml \
--zone=SOURCE_DNS_ZONE \
--zone-file-format
This generates a file like exported-dns.yaml
containing all the DNS entries (except SOA and NS records).
#############################################################################
Another Approach:
If at all the above said approach doesn't work, then follow this alternative approach:
Export your record sets:
gcloud dns record-sets export exported-dns.yaml --zone $YOUR_ZONE --project project-a
Create a managed zone in project-b
gcloud dns managed-zones create $NAME --dns-name=your.com. --description $DESC --project project-b
Import the record sets. Before you do this you will need to remove to standard records.
Edit the exported-dns.yaml that was created above when you exported the record-sets and remove two items that look exactly like the following:
---
kind: dns#resourceRecordSet
name: example.com.
rrdatas:
- ns-cloud-c1.googledomains.com.
- ns-cloud-c2.googledomains.com.
- ns-cloud-c3.googledomains.com.
- ns-cloud-c4.googledomains.com.
ttl: 21600
type: NS
---
kind: dns#resourceRecordSet
name: example.com.
rrdatas:
- ns-cloud-c1.googledomains.com. cloud-dns-hostmaster.google.com. 14 21600 3600 259200
300
ttl: 21600
type: SOA
After you've saved the file import it to your new managed zone in project-b
#############################################################################
Step 2: Create a DNS Zone in the Destination Project
# Set destination project
gcloud config set project DESTINATION_PROJECT_ID
# Create a new managed DNS zone
gcloud dns managed-zones create DEST_ZONE_NAME \
--dns-name="example.com." \
--description="Migrated DNS zone"
Replace example.com.
with your domain name.
Step 3: Import Records into the New Zone
gcloud dns record-sets import exported-dns.yaml \
--zone=DEST_ZONE_NAME \
--zone-file-format \
--delete-all-existing
⚠️ Warning: This will delete all existing records in the destination zone before importing. Use cautiously in production.
Step 4: Update Domain Registrar (If Needed)
If you're transferring the entire DNS zone (not just copying records), make sure to update your domain registrar with the new NS records from the destination project.
gcloud dns managed-zones describe DEST_ZONE_NAME
Look for nameServers
and update them at your domain registrar.
✅ Tips & Best Practices
- Double-check TTL and priority values (especially for MX records).
- Back up DNS records before importing/exporting.
- Use
--dry-run
when testing import commands. - Propagate DNS changes outside of low-traffic hours to avoid disruptions.
🎯 Final Thoughts
While Google Cloud doesn’t support a direct zone transfer across projects, moving DNS entries is simple using the export/import approach with gcloud
. This process is reliable, repeatable, and useful for multi-project setups or consolidating infrastructure.
No comments