Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 35 ยท Droplets and Networking

Reserved IPs and DNS on DigitalOcean: Domains, Records and Failover

Point a domain at a Droplet with DigitalOcean DNS, learn A, AAAA, CNAME, MX and TXT records and TTLs, and use a Reserved IP to move a public address between Droplets for failover.

A Droplet's public IP address belongs to that Droplet. Destroy the Droplet and the address is gone, and everything that pointed at it breaks. Two tools solve this. DNS gives your service a human-friendly name that you can repoint, and a Reserved IP is a static public address that you can move from one Droplet to another in seconds. Together they make deployments and failovers painless.

DigitalOcean DNS

DNS translates names such as www.example.com into IP addresses. To use DigitalOcean's name servers:

  1. Add your domain in the control panel under Networking then Domains (or doctl compute domain create example.com).
  2. At your registrar, change the domain's name servers to ns1.digitalocean.com, ns2.digitalocean.com and ns3.digitalocean.com.
  3. Create records in DigitalOcean.

DNS hosting is free. Propagation after a name-server change can take from minutes to a day, depending on caching.

Record types you need

Type Purpose Example
A Name to IPv4 address @ -> 203.0.113.10
AAAA Name to IPv6 address @ -> 2001:db8::10
CNAME Alias to another name (not allowed at the zone apex) www -> example.com.
MX Mail servers, with a priority @ -> 10 mail.example.com.
TXT Free text: SPF, DKIM, DMARC, verification codes @ -> "v=spf1 include:... -all"
CAA Which certificate authorities may issue certificates @ -> 0 issue "letsencrypt.org"
NS Name servers of the zone or a delegated subdomain lab -> ns1.other.net.

@ stands for the bare domain (the zone apex). A record has a TTL (time to live): how many seconds resolvers may cache the answer. Use a low TTL (60-300 seconds) shortly before a planned migration, then raise it again for stability.

Terminal
doctl compute domain create example.com
doctl compute domain records create example.com --record-type A --record-name @ --record-data 203.0.113.10 --record-ttl 300
doctl compute domain records create example.com --record-type CNAME --record-name www --record-data @ --record-ttl 300
doctl compute domain records list example.com

Reserved IPs

A Reserved IP (previously called a floating IP) is a static public IPv4 address you reserve for your account in one region. You assign it to a Droplet, and traffic sent to it reaches that Droplet. Unassign and reassign it to another Droplet in the same region and the same address now leads to the new server.

Key facts:

  • Regional: it can move only among Droplets in its region.
  • A Droplet can have its normal public IP and a Reserved IP.
  • It is free while assigned to a Droplet, but you are charged for a reserved address that is not assigned, to discourage hoarding.
  • The Droplet's operating system must be configured to answer on it; official images are set up for this through an "anchor IP" and need no manual work.
Terminal
doctl compute reserved-ip create --region fra1
doctl compute reserved-ip-action assign 198.51.100.77 314159
doctl compute reserved-ip-action unassign 198.51.100.77
doctl compute reserved-ip list

The blue-green and failover pattern

Reserved IPs let you swap servers with almost no downtime:

flowchart LR
  DNS["example.com<br/>A 198.51.100.77"] --> RIP(("Reserved IP<br/>198.51.100.77"))
  RIP -- "before" --> OLD["web-blue<br/>(old version)"]
  RIP -- "after reassign" --> NEW["web-green<br/>(new version)"]

Build and test the new Droplet, then move the Reserved IP. If it misbehaves, move it back.

  1. Build web-green with the new release and test it by its own IP.
  2. Reassign the Reserved IP from web-blue to web-green.
  3. Watch for errors. Roll back by reassigning to web-blue.
  4. Destroy the old Droplet when you are sure.

The same trick handles a failed server: a monitoring script that detects a dead Droplet reassigns the IP to a standby. For multiple active servers you do not need this: a load balancer does the job and also spreads load.

DNS versus Reserved IP

Approach Switch speed Good for
Change the DNS record Depends on TTL and resolver caches (minutes or more) Planned moves, region changes
Move a Reserved IP Seconds, no cache to wait for Blue-green, failover within a region
Load balancer Instant health-based routing Multiple servers, high availability

Use all of them together: DNS points at the Reserved IP or load balancer, and you move things behind the address.

Stand-in: model a zone and a reassignment

The first program validates and prints a tiny DNS zone, checking the rule that a CNAME cannot sit beside other records of the same name. The second models Reserved IP moves. Both are stand-ins with no network access.

Python Stand-in: validate DNS records

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: Reserved IP assignment and rollback

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Practical advice

  • Lower the TTL a day before a migration and raise it afterwards.
  • Add both A and AAAA only if the server really answers on IPv6.
  • Keep SPF, DKIM and DMARC TXT records if you send email from the domain, or messages will land in spam.
  • Delete Reserved IPs you no longer use; unassigned ones are billed.
  • DigitalOcean DNS is authoritative DNS only: it does not register domains. Buy the domain at a registrar first.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which record type maps a name to an IPv4 address?

    An A record holds an IPv4 address; AAAA holds IPv6.
  2. 2. Why can't you put a CNAME at the zone apex (@)?

    A CNAME cannot coexist with other records for the same name, and the apex must carry NS and SOA records.
  3. 3. What is a Reserved IP good for?

    Reassigning it enables blue-green deploys and failover within its region.
  4. 4. What happens if a Reserved IP is not assigned to any Droplet?

    Unassigned Reserved IPs incur charges, so release them when unused.
  5. 5. Why lower a record's TTL before a planned migration?

    A short TTL limits how long old answers stay cached.

Summary

  • DigitalOcean DNS hosts your zone for free once you point your registrar's name servers to it; learn A, AAAA, CNAME, MX, TXT and CAA records and the TTL.
  • A Reserved IP is a regional static address you can reassign between Droplets in seconds; it is billed when idle.
  • Use DNS for planned moves, Reserved IPs for fast switches, and load balancers for multiple servers.

Next: Volumes: Block Storage for Droplets