Skip to content

kennycoder/gcp-diy-dyndns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DIY Dynamic DNS on Google Cloud Functions

License Python Terraform

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!

Getting Started

Prerequisites

Deploying

Before anything, make sure you are authenticated to Google Cloud Platform:

  1. Run gcloud auth login and gcloud auth application-default login.
  2. Enable necessary APIS:
gcloud services enable cloudbuild.googleapis.com \
cloudfunctions.googleapis.com \
run.googleapis.com \
dns.googleapis.com

Deploying

  1. Navigate to terraform folder.
  2. Customize terraform.tfvars based on terraform.tfvars.template.
  3. Run: terraform init, terraform plan, terraform apply
  4. 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

Deploying changes

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

Usage

  1. On your home machine/server/raspberrypi (ideally the one that runs 24/7), setup a cronjob via crontab -e

  2. 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).

  3. Check the /tmp/diydyndns-domain.log to see if it's working. By default it runs every 30 minutes.

License

Apache License 2.0. See the LICENSE file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published