A managed zone is the container for all of your DNS records that
share the same DNS name prefix, for example,
example.com. Managed zones
are automatically assigned a set of name servers when they are created to handle
responding to DNS queries for that zone. A managed zone has quotas for the
number of resource records that it can include.
Before you begin
The Google Cloud DNS API requires that you create a Google Cloud DNS project and enable the Cloud DNS API.
If you are creating an application that will use the REST API, you will also need to create an OAuth 2.0 client ID.
- If you don't already have one, sign up for a Google account.
- Enable the Google Cloud DNS API in the Cloud Platform Console. You can choose an existing Compute Engine or App Engine project, or you can create a new project.
- If you need to make requests to the REST API, you will need to create an OAuth 2.0 ID: Setting up OAuth 2.0.
Note the following information in the project that you will need to input in
The client ID (
- The project ID that you wish to use. You can find the ID at the top of the Overview page in the Cloud Platform Console. You could also ask your user to provide the project name that they want to use in your app.
- The client ID (
If you have not run the
gcloud command-line tool previously, you will need
to run the following command to specify the project name and authenticate with
the Cloud Platform Console:
gcloud auth login
You can also specify the
--project parameter for a command to operate against
a different project for that invocation.
Creating managed zones
When you get started with Cloud DNS API, you will need to create a managed zone to contain your DNS records. The managed zone is connected to your Google Cloud DNS project. Note that when you create a zone, the new zone won't be used until you update your domain registration, or explicitly point some resolver at, or directly query, one of your zone's name servers.
To create a zone, you must provide the DNS zone name, a description, and a name to identify the zone:
gcloud dns managed-zones create --dns-name="example.com." --description="A zone" "myzonename"
def create_zone(project_id, name, dns_name, description): client = dns.Client(project=project_id) zone = client.zone( name, # examplezonename dns_name=dns_name, # example.com. description=description) zone.create() return zone
If you receive an
accessNotConfigured error, you must
enable the Cloud DNS API.
Listing managed zones
To list all of your zones within a project:
gcloud dns managed-zones list
def list_zones(project_id): client = dns.Client(project=project_id) zones = client.list_zones() return [zone.name for zone in zones]
Getting managed zone details
To get details about your managed zone, such as if you need to look up the associated name servers:
gcloud dns managed-zones describe "myzonename"
def get_zone(project_id, name): client = dns.Client(project=project_id) zone = client.zone(name=name) try: zone.reload() return zone except NotFound: return None
Deleting managed zones
To delete a zone, provide the zone name to the delete command:
gcloud dns managed-zones delete "myzonename"
Note that only empty zones can be deleted. An empty managed-zone has only SOA and NS record-sets. You can easily empty a zone using the import command as follows:
touch empty-file gcloud dns record-sets import -z "myzonename" --delete-all-existing empty-file rm empty-file
def delete_zone(project_id, name): client = dns.Client(project=project_id) zone = client.zone(name) zone.delete()