DIYDynDNS is a simple api endpoint that listens for HTTPs requests, extracts the IP address of the caller (via X-Forwarded-For header) and updates the specified A entry to point to that IP address.
Whole purpose of this mini-project is to overcome the dynamic ip allocation by most ISPs.
⚠️ Make sure that the API key is safely stored, otherwise anyone would be able to update your DNS records!
- Google Cloud project/account
- gcloud cli
- Terraform
Before anything, make sure you are authenticated to Google Cloud Platform:
- Run
gcloud auth login
andgcloud auth application-default login
. - Enable necessary APIS:
gcloud services enable cloudbuild.googleapis.com \ cloudfunctions.googleapis.com \ run.googleapis.com \ dns.googleapis.com
- Navigate to
terraform
folder. - Customize
terraform.tfvars
based onterraform.tfvars.template
. - Run:
terraform init
,terraform plan
,terraform apply
- Check the output to get the URL for your newly deployed service or get it via the following command:
gcloud run services list | grep -i diydns-function
In case you made some customization to the code, you can easily push the changes with gcloud (from project's root folder):
export REGION=REGION_YOU_SET_IN_TERRAFORM_TFVARS gcloud functions deploy diydns-function \ --gen2 \ --region=${REGION} \ --runtime=go122 \ --source=. \ --entry-point=handleHTTP \ --trigger-http
-
On your home machine/server/raspberrypi (ideally the one that runs 24/7), setup a cronjob via
crontab -e
-
Use this template:
30 * * * * curl -s "https://{CLOUD_FUNCTION_URL}/?key={YOUR_SECRET_KEY}&zone={YOUR_MANAGED_DNS_ZONE}&domain={YOUR_DNS_ENTRY_NAME}." >> /tmp/diydyndns-domain.log 2>&1
❗ Yes, there is dot at the end of the domain entry - e.g.:
subdomain.domain.tld.
ℹ️ This will run every 30 minutes, but you can adjust this number in the beginning of the line (from 30 to 60 for example).
-
Check the
/tmp/diydyndns-domain.log
to see if it's working. By default it runs every 30 minutes.
Apache License 2.0. See the LICENSE file.