Dynamic DNS using Apache Libcloud
A small, easy-to-use, Python implementation of dynamic DNS update agent.
- Google Cloud user account
- A GCP project with enabled billing
- An active domain name with a corresponding Zone name configured in the Google Cloud Platform Console
- Credentials with the proper DNS permission
Create service account for the DNS update agent
THIS SECTION WILL BE UPDATED SOON TO PROVIDE MORE DETAILED EXPLENATION OF HOW TO CREATE CREDENTIALS
From Google Cloud Platform's service accounts management, add a service account with a DNS Administrator role and write down the Service Account ID. After the account is created, create a corresponding key in a JSON file format.
You'll be using the Service Accoung ID and the JSON key-file to access and update your cloud zone.
Clone and configure:
- Clone the repo using
git clone firstname.lastname@example.org:orpolaczek/libcloud-dynamic-dns.git
- Place the JSON key-file you've downloaded from Google under the
- Open and edit the
config/__init__.pyfile and update all it's fields to match your Google Service Account and Cloud Project Name.
The config file:
class Config: DNS_USER_ID = "SERVICE_ACCOUNT_NAME@YOUR_PROJECT.iam.gserviceaccount.com" # The GCP Service Account ID DNS_KEY = "config/key.json" # The path to the JSON-key file (relative to the project's root) DNS_PROJECT_NAME = "YOUR_PROJECT" # Your Google Cloud Platform project name # Example settings for creating an test.mydomain.com A record that points to your current IP A_RECORD_TTL_SECONDS = 3600 # The desired TTL for your DNS record A_RECORD_NAME = "test" # The record name A_RECORD_ZONE_NAME = "mydomain.com." # The domain zone name (usually- the domain with an ending `.`)
Running the update agent
- Install the dependencies using
pip install -r requirements.txt
- Run the Python update agent using
After running the Python file, a successfull run would look as the following:
➜ libcloud-dynamic-dns git:(master) ✗ python update_dns.py Setting A record: test.mydomain.com. to point: 18.104.22.168 SUCCESS
In order to run the update agent periodically - use a cronjob :)
Please feel free to send feedback to email@example.com .
If you're willing to contribute changes/additions you've made to this code feel free to create a PR. There's always room for improvement!
This implementation of dynamic DNS using Libcloud is provided under MIT license.