DEV Community

Cover image for Free dynDNS for your NAS: auto-update DNS with your latest IP
Guillaume ÉgÊe for Serverless By Theodo

Posted on • Updated on

Free dynDNS for your NAS: auto-update DNS with your latest IP

🎉 No more use a costly dynDNS service to update DNS A record when your IP changes!

I've just set up a NAS at home and linked a domain name to my router IP. But one day I could no more access to it, because the router IP changed without any notice!
Fortunately, a lot of dynDNS tools exist, but they are often paid services (even if quite cheap, I acknowledge). Why not building your own free dynDNS?

I created a repository which rely on an AWS CDK stack to update your A record in Amazon Route 53 with an API endpoint. This endpoint can be called by a script whenever your IP changes.

Suppose you host your own NAS server and want to access it at my-server.com you have bought on AWS. You need to add a A record to make my-server.com point to your server public IP. In general, if you rely on an Internet provider to get an IP, you are not guaranteed to have a one static, even if in practice they don't often change (at router reboot for instance). If you want to keep your A record up-to-date when your dynamic IP changes, this project is made for you!

... and it is (almost) free!

Set up the stack

Just follow the installation steps!
You'll need Node.js, an AWS account and a domain name of course!

How it works?

Image description

The script installed on your NAS will first call an API to retrieve its current IP, on a frequency defined with a cron job.
If this IP has changed, it will call another API endpoint (protected with an API key this time). An express step functions will then update the record in Route53 if the requested IP is the same as the source IP (the actual IP of the server calling the endpoint).
That's all!

🤑 Estimated cost

The deployed stack uses AWS resources at really low cost, supposing the script is run every hour and the IP changes every day:

Check the IP (every hour)

  • API Gateway V2: ~ $0.00083 = 31 days x 24h x 1.11/million requests. NB: free tier the first year
  • Lambda: ~ $0.00126 / month = 31 days x 24h x 1000 milliseconds x $0.0000000017 (architecture ARM, memory: 128 MB, region eu-west-1, Jan. 2024)

Update the IP (every day)

  • Step Functions: ~ $0.033 / month = 31 days x ($0.000001 (price per request, Jan. 2024) + 1000 milliseconds x 64 MB x \$0.00001667 )
  • CloudWatch: Free tier = 6 months x 31 days x (2 kB (Step Functions) + 500 B (Lambda)) = 0.5 MB < 5 GB of free tier
  • API Gateway V1: ~ $0.00003 = 31 x 3.50/million requests. NB: free tier the first year
  • Route 53 : ~ $0.00001 / month = 31 queries x $0.40 per million queries
  • CloudFormation : free
  • IAM: free

TOTAL COST: < $0.5 per year!

NB: you need to add the domain name cost (~$12 per year (depending on the name chosen) + $0.50 per hosted zone per month).

Top comments (0)