Managing Records

Managing DNS records for the Google Cloud DNS API involves sending change requests to the API. These changes consist of additions and deletions to your resource record sets collection. You can easily send the desired changes to the API using the import, export, and transaction commands, as described below.

Before you begin

You must have already created a managed zone and completed the prerequisites for that task.

For all the gcloud command-line examples below, you can also specify the --project parameter for a command to operate against a different project for that invocation.

Importing and exporting record-sets

You can use import and export to copy record-sets into and out of a managed zone. The formats you can import from and export to are either BIND zone file format, or YAML records format.

To import record-sets, you use the dns record-sets import command. The --zone-file-format flag tells import to expect a BIND zone formatted file. If you omit this flag, import expects a YAML formatted records file:

gcloud dns record-sets import -z=examplezonename --zone-file-format path-to-example-zone-file

To export record-sets, you use the dns record-sets export command. Use the --zone-file-format flag to tell export to export the record-sets into a BIND zone formatted file. If you omit this flag, export exports the record-sets into a YAML formatted records file:

gcloud dns record-sets export -z=examplezonename --zone-file-format

Modifying records using transactions

You modify DNS records by creating and executing a transaction that specifies the operations you want to perform. A transaction is a group of one or more record changes that should be propagated together. Thus the entire transaction either succeeds or fails, so your data is never left in an intermediate state.

To modify DNS records, you first start a transaction:

gcloud dns record-sets transaction start -z=examplezonename

When you start a transaction, Cloud DNS creates a local file in YAML format called transaction.yaml. As you specify operations through the command line, they are added to this file.

For example, this command appends an A record addition to the transaction:

gcloud dns record-sets transaction add -z=examplezonename --name="" --type=A --ttl=300 “”

If you want to view the contents of the transaction.yaml file, use the describe command:

gcloud dns record-sets transaction describe -z=examplezonename

You can even edit transaction.yaml in a text editor to manually make additions, deletions, or corrections.

When you've finished specifying your operations, either through the command line or by editing the transaction.yaml file directly, you can execute the transaction as follows:

gcloud dns record-sets transaction execute -z=examplezonename

Once you execute or abort the transaction, the transaction.yaml file is deleted.

Displaying the current record set

To display the current DNS records for your zone:

Command line

gcloud dns record-sets list --zone="myzonename"
The command will output the JSON response for the resource record set for the first 100 records. You can specify these additional parameters:
  • limit: Maximum number of record-sets to list.
  • name: Only list record-sets with this exact domain name.
  • type: Only list records of this type. If present, the --name parameter must also be present.


def list_resource_records(project_id, zone_name):
    client = dns.Client(project=project_id)
    zone =

    records = zone.list_resource_record_sets()

    return [(, record.record_type, record.ttl, record.rrdatas)
            for record in records]

See also

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud DNS Documentation