google-cloud-dns overview (2.18.0)

com.google.cloud.dns

A client for Cloud DNS - A highly available global DNS network.

Here are two simple usage examples from within Compute/App Engine.

The first snippet shows how to create a zone resource. The complete source code can be found on CreateZone.java. Note that you need to replace the domainName with a domain name that you own and the ownership of which you verified with Google.


Dnsdns=DnsOptions.getDefaultInstance().getService();
StringzoneName="my-unique-zone";
StringdomainName="someexampledomain.com.";
Stringdescription="This is a google-cloud-dns sample zone.";
ZoneInfozoneInfo=ZoneInfo.of(zoneName,domainName,description);
ZonecreatedZone=dns.create(zoneInfo);

The second example shows how to create records inside a zone. The complete code can be found on CreateOrUpdateRecordSets.java.


Dnsdns=DnsOptions.getDefaultInstance().getService();
StringzoneName="my-unique-zone";
Zonezone=dns.getZone(zoneName);
Stringip="12.13.14.15";
RecordSettoCreate=RecordSet.newBuilder("www.someexampledomain.com.",RecordSet.Type.A)
.setTtl(24,TimeUnit.HOURS)
.addRecord(ip)
.build();
ChangeRequestInfochangeRequest=ChangeRequestInfo.newBuilder().add(toCreate).build();
zone.applyChangeRequest(changeRequest);

When using google-cloud from outside of App/Compute Engine, you have to specify a project ID and provide credentials. See Also: Google Cloud DNS

com.google.cloud.dns.spi

com.google.cloud.dns.spi.v1

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.