-
-
Save digitaljhelms/a1f1d9e2d8aaa3838571 to your computer and use it in GitHub Desktop.
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>KeepAlive</key> | |
| <false/> | |
| <key>Label</key> | |
| <string>com.dnsimple.dynamicdns</string> | |
| <key>LowPriorityIO</key> | |
| <true/> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/usr/local/bin/DNSimpleUpdater</string> | |
| </array> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| </dict> | |
| </plist> |
| #!/bin/bash | |
| AUTH_EMAIL='your@email' # dnsimple account email address | |
| AUTH_TOKEN='your-api-token' # dnsimple api token | |
| DOMAIN_ID='yourdomain.com' # domain name or id | |
| RECORD_ID='12345' # record id to update | |
| IP="`curl http://icanhazip.com/`" | |
| curl -H "X-DNSimple-Token: $AUTH_EMAIL:$AUTH_TOKEN" \ | |
| -H "Accept: application/json" \ | |
| -H "Content-Type: application/json" \ | |
| -X PUT \ | |
| -d "{\"record\":{\"content\":\"$IP\"}}" \ | |
| https://api.dnsimple.com/v1/domains/$DOMAIN_ID/records/$RECORD_ID | |
Note: Ensure the record you're updating is an A record type. While it's not mentioned in the DNSimple API documentation, if the DNS record being updated [with an IP address] is a CNAME record type (and likely other types as well) the API call will fail with the following response: {"message":"Validation failed","errors":{"content":["must be a domain name"]}} Strangely, however, an IP address can be assigned as the value of a CNAME record type when using the website.
At this point it should not be possible to use an IP address in a CNAME from the site either. I recently added a validation that will prohibit that, which is probably what caused the problem to appear for you recently.
Couple of things changed since then... API is now v2, which is a bit different. The canihazip.com service you need to specify -4 to return ipv4 ip otherwise you just get an error from dnsimple saying it's not valid.
IP=$(curl -4 https://icanhazip.com)
curl -H 'Authorization: Bearer <token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X PATCH \
-d "{\"content\":\"$IP\"}" \
https://api.dnsimple.com/v2/:account_id/zones/:domain_id/records/:record_id
Usage:
DNSimpleUpdaterfile~/.DNSimpleUpdatercd ~/.DNSimpleUpdaterDNSimpleUpdaterconfigln -s DNSimpleUpdater /usr/local/binln -s com.dnsimple.dynamicdns.plist ~/Library/LaunchAgentslaunchctl load ~/Library/LaunchAgents/com.dnsimple.dynamicdns.plistUpon all future startups, the DNSimpleUpdater will run automatically and update the DNS entry with your current IP address each time.