Goal
You want a public domain such as example.com (or a subdomain such as cloud.example.com) answered by OCI DNS. You also want record changes you can script and review, so that nobody edits production DNS by hand in the Console during an incident.
This post covers public zones only. Private views and resolver endpoints are a separate topic.
1. Before you start
Check these first:
- You can edit the NS records at the registrar, or in the parent zone if you are delegating a subdomain.
- Your group has
manage dnsin the target compartment. A minimal policy:
Allow group DnsAdmins to manage dns in compartment network-prod
- You know the current TTLs. If the domain is already live elsewhere, export its records first so you can import or recreate them before you switch name servers.
Warning
Changing name servers at the registrar while the new zone is empty or incomplete takes the domain offline for as long as resolvers cache the old NS records. Copy every record first, test against the OCI name servers, then delegate.
2. Create the zone
C=ocid1.compartment.oc1..aaaa...
oci dns zone create \
--compartment-id "$C" \
--name example.com \
--zone-type PRIMARY
Public zones use the GLOBAL scope, which is the default. Get the name servers that OCI assigned to the zone. You need them for delegation:
oci dns zone get --zone-name-or-id example.com \
--query 'data.nameservers[].hostname' --output table
The zone starts with SOA and NS records only. List everything in it with:
oci dns record zone get --zone-name-or-id example.com --output table
If you are moving from another provider, OCI can create a zone from a standard zone file. See oci dns zone create-zone-from-zone-file --help for the parameters in your CLI version. Exports from some providers need cleaning first, for example removing provider-specific record types or proxy flags.
3. Add records
Each record set (RRset) is a name plus a type. rrset update replaces the whole RRset with the items you pass, so always send the complete set of values for that name and type.
# A record for www
oci dns record rrset update \
--zone-name-or-id example.com \
--domain www.example.com --rtype A \
--items '[{"domain":"www.example.com","rtype":"A","rdata":"203.0.113.10","ttl":300}]' \
--force
# Two A records for api (round robin) - both must be in the same call
oci dns record rrset update \
--zone-name-or-id example.com \
--domain api.example.com --rtype A \
--items '[
{"domain":"api.example.com","rtype":"A","rdata":"203.0.113.21","ttl":300},
{"domain":"api.example.com","rtype":"A","rdata":"203.0.113.22","ttl":300}
]' --force
# CNAME and TXT
oci dns record rrset update --zone-name-or-id example.com \
--domain portal.example.com --rtype CNAME \
--items '[{"domain":"portal.example.com","rtype":"CNAME","rdata":"www.example.com.","ttl":300}]' --force
oci dns record rrset update --zone-name-or-id example.com \
--domain example.com --rtype TXT \
--items '[{"domain":"example.com","rtype":"TXT","rdata":"\"v=spf1 include:_spf.example.net -all\"","ttl":3600}]' --force
Check the result:
oci dns record rrset get --zone-name-or-id example.com \
--domain api.example.com --rtype A --output table
Tip
Put a trailing dot on hostnames in
rdatafor CNAME, MX and NS records (www.example.com.). Without it, some tools treat the value as relative to the zone, and you end up pointing atwww.example.com.example.com.
4. Test before you delegate
Query an OCI name server directly. This works before the registrar knows about the zone:
NS=$(oci dns zone get --zone-name-or-id example.com \
--query 'data.nameservers[0].hostname' --raw-output)
dig @"$NS" www.example.com A +short
dig @"$NS" example.com TXT +short
dig @"$NS" example.com SOA +short
Compare each answer with the old provider's answer for the same names. Every name your applications, mail and certificate validation use must match.
5. Delegate
At the registrar, replace the domain's name servers with the hostnames from step 2. For a subdomain such as cloud.example.com, add NS records for cloud in the parent zone instead.
Before the change, lower the TTL on the parent's NS records if your registrar lets you. Then watch the delegation propagate:
dig example.com NS +short
dig +trace www.example.com A
+trace shows each step from the root servers down. The final referral must point at the OCI name servers. Old answers can still appear until cached NS records expire, so keep the old provider's zone running and unchanged for at least that long.
6. Change and remove records without touching the rest
Use domain patch with ADD or REMOVE operations to change one value in an RRset and leave the others alone:
# Take one api backend out of round robin
oci dns record domain patch \
--zone-name-or-id example.com \
--domain api.example.com \
--items '[{"operation":"REMOVE","domain":"api.example.com","rtype":"A","rdata":"203.0.113.22"}]'
Delete a whole RRset:
oci dns record rrset delete --zone-name-or-id example.com \
--domain portal.example.com --rtype CNAME --force
Caution
oci dns record zone updatereplaces every record in the zone with the items you pass. Use it only to restore a full export. For day-to-day changes userrset update(one name and type) ordomain patch(single values).
7. Back up the zone
Export the zone file before each change window and keep it in version control or Object Storage:
oci dns zone get-zone-content \
--zone-name-or-id example.com \
--file "example.com.$(date +%F).zone"
The SOA serial goes up with every change. Record it with the export so you can match an outage to a change:
oci dns zone get --zone-name-or-id example.com \
--query 'data.{serial:serial,"version":version,updated:"time-created"}'
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
dig @<oci-ns> returns the record but public lookups don't | Registrar still lists the old name servers | Fix the NS at the registrar, then check with dig +trace |
| Only one of two A values remains | rrset update sent with one item | Resend the full set, or use domain patch with ADD |
| CNAME create fails | Another record type already exists at that name, or the name is the zone apex | Remove the conflicting RRset; use A/AAAA at the apex |
CNAME resolves to name.example.com.example.com | Missing trailing dot in rdata | Use the fully qualified name ending in . |
412 Precondition Failed from scripts | Zone changed since your script read its ETag | Re-read the record, then retry with the new --if-match value |
404 NotAuthorizedOrNotFound | Zone is in another compartment, or the policy is missing dns | Pass the zone OCID, or fix the policy |
Prevent it next time
- Keep records in Terraform (
oci_dns_rrset) or in a reviewed JSON file applied withrrset update, not in Console edits. - Export the zone with
get-zone-contentbefore every change, and on a schedule. - Use 300-second TTLs on records you expect to fail over or migrate, and longer TTLs on stable ones such as MX and TXT.
- Grant
manage dnsonly to the network team. Application teams that need one record can use a compartment-scoped zone for their subdomain. - Alert on zone changes with an Events rule on DNS record and zone update events, and check OCI Audit to see who changed what.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get