Joeri Verdeyen bio photo

Joeri Verdeyen

Web-engineer, cyclist, Nespresso lover, Strava pusher.

Twitter LinkedIn Instagram Github Stackoverflow Strava

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 as an A record.

 1 #!/bin/bash
 3 # Your domain name
 4 domain=""
 6 # record id to update
 7 record=""
 9 # api key
10 api_key=""
12 # lookup ip
13 ip="$(curl"
15 echo content="$(curl \
16         -k \
17         -H "Authorization: Bearer $api_key" \
18         -H "Content-Type: application/json" \
19         -d '{"data": "'"$ip"'"}' \
20         -X PUT "$domain/records/$record")"

Create a file /usr/bin/ and add the script with your settings. To lake sure you are able to execute the script, add execute permissions.

chmod +x /usr/bin/


Add an entry in /etc/crontab or in the respective cron file.

0 4 * * * /usr/bin/

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:

<input id="domain_record_id" name="domain_record[id]" type="hidden" value="THISISYOURID">

Enjoy your free Dynamic DNS setup!

Thanks for reading

Feel free to leave a comment if you have remarks or like this post