This Go program updates DNS records using the Cloudflare API. It supports both single domain updates and batch processing from a file.
New in v1.3.6: If you omit the IP address argument, the program will automatically detect your current public IP using nslookup myip.opendns.com resolver1.opendns.com.
- Go installed on your system.
- A Cloudflare account with an API token. The token should have permissions to edit DNS records.
- Set the environment variable
CLOUDFLARE_API_KEYwith your Cloudflare API token. The program supports four ways to invoke updates. The preferred form is a single domain/FQDN plus IP. The first argument may also be a path to a domains file for batch updates. Legacy three-argument form is still supported. You can now omit the IP address to auto-detect your public IP.
The program supports three ways to invoke updates. The preferred form is a single domain/FQDN plus IP. The first argument may also be a path to a domains file for batch updates. Legacy three-argument form is still supported.
- Preferred single FQDN form (recommended): resolve zone automatically
update-dns <domain-or-fqdn> <new-ip><domain-or-fqdn>: A fully-qualified domain name such aswww.example.com,example.com, or a path to a domains file (see batch mode below). If a file with this name exists, it will be treated as a domains file.<new-ip>: The new IP address for the DNS record.
Behavior:
- If the first argument is a file path, the program runs in batch mode and treats the file as a list of domains to update.
- If the first argument is a FQDN, the program will automatically determine the Cloudflare zone by trying candidates from left-to-right (e.g.,
www.sub.example.com→ trieswww.sub.example.com,sub.example.com,example.com), using the first matching zone. The portion left of the found zone becomes the record name (or@for the apex/root).
- Batch mode (explicit file):
update-dns <domains-file> <new-ip>You can also omit <new-ip> to auto-detect your public IP for all records in the file:
update-dns <domains-file><domains-file>: Path to a text file containing domain/subdomain entries (one per line).<new-ip>: The new IP address for all DNS records.
- Legacy form (still supported):
update-dns <domain> <subdomain> <new-ip><domain>: The zone (e.g.,example.com).<subdomain>: The record name to update (wwwor@for the root).<new-ip>: The new IP address.
The domains file should contain one domain/subdomain per line. Examples:
www.example.com
api.example.com
mail.subdomain.example.com
.example.com
- Regular entries like
subdomain.domain.comupdate that subdomain's A record. - Entries starting with
.(like.example.com) explicitly indicate the base/apex domain record should be updated.
- The program initializes a connection to the Cloudflare API using the API token.
- It retrieves the zone ID for the specified domain.
- It lists all DNS records for the domain and finds the A record for the specified subdomain.
- If the current IP address matches the new IP address, no changes are made.
- If the IP addresses differ, the program updates the DNS record with the new IP address.
- The program outputs a message indicating the IP address has been updated.
- The program reads the domains file line by line.
- For each domain entry, it parses the domain and subdomain components.
- It processes each domain using the same logic as single domain mode.
- Progress is tracked and reported, showing successful updates and any errors.
- Individual domain failures don't stop the entire batch process.
- Single Mode: The program logs errors and exits if it encounters issues.
- Batch Mode: Individual domain errors are reported but don't stop processing of remaining domains. A summary is provided at the end showing success/failure counts.
go install github.com/jonfleming/update-dns@latestUpdate a subdomain:
update-dns example.com www 192.0.2.1Update the base domain:
update-dns example.com @ 192.0.2.1Update multiple domains from a file:
update-dns domains.txt 192.0.2.1With a domains.txt file containing:
www.example.com
api.example.com
.example.com
mail.anotherdomain.com
This will update:
www.example.com→ 192.0.2.1api.example.com→ 192.0.2.1example.com(base domain) → 192.0.2.1mail.anotherdomain.com→ 192.0.2.1