3.5 KiB
+++ categories = ["software"] tags = ["dns"] date = 2025-02-16T00:00:00Z description = "Deploying an AWS Route 53 and Lambda dynamic DNS solution that updates records whenever a home public IP address changes." draft = false slug = "dynamic-dns" title = "🌐 Dynamic DNS" author = "nicholas" +++
I have a public IP assigned by my ISP, but it is not static, and is therefore subject to change at their whim. This is no good, since I like to be able to access my devices from beyond my local network, and any change in my public IP address will result in misconfigured DNS. A disaster. I need a way to be sure that my any change in my public IP address will trigger an automatic reconfiguration of certain DNS records. I am using AWS Route 53 for my DNS provider, and luckily there is a handy resource available route53-dynamic-dns-with-lambda which perfectly suits my need for DDNS.
Route 53 Dynamic DNS with Lambda
Rather than rehash all of the steps covered in the documentation for this tool, I will simply cover the broad strokes of the process and configuration. The repository linked above basically comes with an installer that walks the user through a few steps to automatically configure the DDNS. The user is left with a simple script that will update the Route 53 DNS records any time the sender IP address changes. This is explained pictographically below.
{{< image src="images/architecture.png" caption="Route 53 Dynamic DNS with Lambda" >}}
AWS CloudShell
{{< image src="images/aws-cloudshell.jpg" caption="AWS Cloudshell" >}}
The guide recommends deploying their Cloud Development Kit using AWS CloudShell session, so this is what I do. The process amounts to cloning the git repo route53-dynamic-dns-with-lambda, running the newrecord.py script contained therein, and following the directions in the CLI bootstrap wizard. The process is basically:
- clone the repo
- change directory to the repo
- install the CDK
- run
newrecord.py
{{< image src="images/aws-cloudshell-newrecord.py.jpg" caption="newrecord.py" >}}
Generate Configuration File
The last step of the install wizard isa prompt appears to confirm all of the settings.
##############################################
# #
# The following configuration will be saved: #
# #
Host name: www.uuard.com
Hosted zone id: ZYZ12345678901234
Record set TTL: 60
Secret: SHARED_SECRET_123
# #
# do you want to continue? (y/n) #
# #
##############################################
And finally the following message is produced, along with a dyndns.sh script.
This can be run via a CRON or SystemD timer to periodically update your hostname.
#####################################################
# #
# The Serverless Dynamic DNS solution is now ready. #
# #
#####################################################
www.uuard.com can be updated with the following command:
./dyndns.sh -m set -u https://xyz1234567890xyz.lambda-url.eu-west-1.on.aws/ -h www.uuard.com -s SHARED_SECRET_123
The only thing left to be done is to move the provided dyndns.sh script to my server and set up a cron job. I chose to run my script each week “At 00:00 on Sunday” (0 0 * * 0).
Done.