Dynamic DNS with the Digital Ocean API
Digital Ocean
DigitalOcean is an American virtual private server provider based in New York City. The company leases capacity from existing datacenters, including sites in New York, Amsterdam, San Francisco, London and Singapore.
Dynamic DNS script
I’ve created a bash script to update an already created A record with the IP of a (home) server.
You can e.g. add server.yourdomain.be
as an A record.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
# Your domain name
domain="yourdomain.be"
# record id to update
record=""
# api key
api_key=""
# lookup ip
ip="$(curl http://ipecho.net/plain)"
echo content="$(curl \
-k \
-H "Authorization: Bearer $api_key" \
-H "Content-Type: application/json" \
-d '{"data": "'"$ip"'"}' \
-X PUT "https://api.digitalocean.com/v2/domains/$domain/records/$record")"
Create a file /usr/bin/dyndns.sh
and add the script with your settings. To lake sure you are able to execute the script, add execute permissions.
Cron
Add an entry in /etc/crontab
or in the respective cron file.
Every night at 4am the script will update the A record with your ip address.
Edit: Where can I find the record id?
Login to your DigitalOcean control panel. Navigate to the given dns domain record.
Find the A record you want to be able to change dynamic. Right click on it and choose inspect element
.
The id is located in the following input field:
Enjoy your free Dynamic DNS setup!
Thanks for reading
Feel free to leave a comment if you have remarks or like this post