A CLI tool written in Go using Cobra to update or insert A records (or other types) for a domain in Cloudflare via the Cloudflare API.
- Update existing DNS records
- Insert (upsert) DNS records if not found
- Add optional comment to records
- Supports TTL and Cloudflare proxy settings
- Reads Cloudflare API token from
--apiToken
flag orCF_API_TOKEN
environment variable
-
Clone the repo:
git clone https://github.com/yourusername/cloudflare-dns-updater.git cd cloudflare-dns-updater
-
Build the binary:
go build -o cf
Prebuilt binaries for all major platforms are available on the Releases page.
Platform | File Name |
---|---|
Linux (amd64) | cf-linux-amd64 |
Linux (arm64) | cf-linux-arm64 |
macOS | cf-darwin-amd64 |
Windows | cf-windows-amd64.exe |
Windows (ARM) | cf-windows-arm64.exe |
curl -L -o cf https://github.com/sagar290/cf/releases/latest/download/cf-linux-amd64
chmod +x cf
./cf --help
cf update:dns [domain] [type] [key] [value] [comment (optional)]
Argument | Description | Required |
---|---|---|
domain | Your domain name (e.g., example.com) | ✅ |
type | DNS record type (e.g., A, CNAME) | ✅ |
key | DNS key to update (e.g., @ , www ) |
✅ |
value | New value (e.g., IP address or CNAME target) | ✅ |
comment | Optional comment for the DNS record | ❌ |
cf update:dns example.com A @ 123.123.123.123 "Main site IP"
This updates or inserts the A record for example.com
with a comment.
Flag | Default | Description |
---|---|---|
--proxied |
true | Whether the record should be proxied |
--ttl |
3600 | Time To Live for the DNS record (in seconds) |
--upsert |
false | Create the record if it doesn't exist |
Set your Cloudflare API token as an environment variable:
export CF_API_TOKEN=your_token_here
✅ Inserted www to 123.123.123.123
Response: {...}
or
✅ Updated www to 123.123.123.123
Response: {...}
- If
--upsert
is not enabled, a missing record will cause an error. - Use
@
to target the root domain. - Comments are supported and visible in Cloudflare dashboard.
This project is licensed under the MIT License.