Dynamic DNS with AWS Route 53

 3 years ago
source link: https://www.gkbrk.com/2020/10/aws-route53-dynamic-dns/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Dynamic DNS with AWS Route 53

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.


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


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

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

rm "${DNS}"


If you find this work useful, please cite it as:

  title = "Dynamic DNS with AWS Route 53",
  author = "Gokberk Yaltirakli",
  journal = "gkbrk.com",
  year = "2020",
  url = "https://www.gkbrk.com/2020/10/aws-route53-dynamic-dns/"

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK