Dynamic DNS with AWS Route 53


Reading time: about 1 minute

I occasionally need to SSH into my laptop, or use other services hosted on it, but my ISP gives me a dynamic IP. While it is stable most of the time, it does occasionally change.

To work around this, I had previously set up a cron job that curl’s a specific URL on my website, and I could get the IP by grep-ing through my server logs. But this is both time-consuming and requires me to update the IP address on different applications every time it changes.

I wanted to have a subdomain that always pointed to my laptop, so I used the AWS CLI to create a DIY dynamic DNS. It fetches your IP from the AWS endpoint, but any source can be used. You can also host this on a server or a serverless function to get the client IP and require less dependencies.

Here’s the shell script that runs every X minutes on my laptop in order to update the domain record.

#!/bin/sh

IP="$(curl -s http://checkip.amazonaws.com/)"

DNS="$(mktemp)"

cat > "${DNS}" <<EOF
{
  "Comment": "DDNS update",
  "Changes": [
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "ResourceRecords": [
          {"Value": "${IP}"}
        ],
        "Name": "subdomain123.gkbrk.com",
        "Type": "A",
        "TTL": 300
      }
    }
  ]
}
EOF

aws route53 change-resource-record-sets \
    --hosted-zone-id "/hostedzone/ZONEID" \
    --change-batch "file://${DNS}"

rm "${DNS}"

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakli202010awsroute53dynamicdns,
  title   = "Dynamic DNS with AWS Route 53",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2020",
  url     = "https://www.gkbrk.com/2020/10/aws-route53-dynamic-dns/"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Dynamic DNS with AWS Route 53", October, 2020. [Online]. Available: https://www.gkbrk.com/2020/10/aws-route53-dynamic-dns/. [Accessed Nov. 12, 2024].
APA Style
Yaltirakli, G. (2020, October 26). Dynamic DNS with AWS Route 53. https://www.gkbrk.com/2020/10/aws-route53-dynamic-dns/
Bluebook Style
Gokberk Yaltirakli, Dynamic DNS with AWS Route 53, GKBRK.COM (Oct. 26, 2020), https://www.gkbrk.com/2020/10/aws-route53-dynamic-dns/

Comments

© 2024 Gokberk Yaltirakli