Digital Ocean Dynamic DNS
I wrote a Python script to update DNS records managed by Digital Ocean. This might be useful for home servers with dynamic IP addresses.
The script queries the ipify API to get the public IPv4 and IPv6 addresses of the server running the script. Each specified record in a specified domain is then updated, if, and only if, the A or AAAA record known by Digital Ocean does not match the corresponding IP address returned by ipify.
Note: This project is managed on Codeberg.
Installation is straightforward.
Clone the Repository
git clone https://gitlab.com/Symplectos/digital-ocean-dynamic-dns.git DigitalOceanDynamicDNS
Create Python Environment
cd DigitalOceanDynamicDNS python3 -m venv env
The script requires the requests library. All requirements can be installed by invoking pip:
source bin/env/activate pip install -r requirements
To configure doDynDNS, a .do.conf file must be created in the root folder of the project:
The configuration requires two sections, a DigitalOcean section containing a valid API Access Key, and a DNS section, containing the specific domain and specific records to update. Multiple records can be specified by simply putting each record into a new line:
[DigitalOcean] key = *** [DNS] domain = myDomain.eu records = sub1 sub2
To automatically run the script periodically, create a cronjob
*/5 * * * * cd /pathToFolder && /pathToFolder/env/bin/python3 /pathToFolder/doDynDNS.py
To manually run the script, activate the environment and then invoke the Python interpreter.
Activate the Environment
The script automatically logs its last run in the doDynDNS.log file.