Skip to content

Instantly share code, notes, and snippets.

@lantrix
Forked from TonyFNZ/dnsupdate.sh
Last active March 1, 2022 18:39
Show Gist options
  • Select an option

  • Save lantrix/3f8fbe8c8b18469d0472279634d90fb9 to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/3f8fbe8c8b18469d0472279634d90fb9 to your computer and use it in GitHub Desktop.

Revisions

  1. lantrix revised this gist Jan 18, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions dnsupdate.sh
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,12 @@ cat > ./dnsupdate.json <<EOF
    {
    "Action": "UPSERT",
    "ResourceRecordSet": {
    "Name": "$domain_name",
    "Name": "${domain_name}",
    "Type": "A",
    "TTL": 300,
    "ResourceRecords": [
    {
    "Value": "$ip_address"
    "Value": "${ip_address}"
    }
    ]
    }
  2. lantrix revised this gist Jan 18, 2019. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions dnsupdate.sh
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    #!/bin/bash

    hosted_zone_id="<your Route53 hosted zone id>"
    domain_name="<your domain name>"
    hosted_zone_id='Z57Q212345678'
    domain_name='server.example.com'

    # Abort script on any errors
    set -e

    # Get new IP address
    ip_address=`curl http://169.254.169.254/latest/meta-data/public-ipv4`
    ip_address=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)

    # Build temporary file
    cat > ./dnsupdate.json <<EOF
    @@ -31,5 +31,4 @@ cat > ./dnsupdate.json <<EOF
    EOF

    # Call Route53 to update DNS
    aws route53 change-resource-record-sets --hosted-zone-id $hosted_zone_id --change-batch file://./dnsupdate.json

    aws route53 change-resource-record-sets --hosted-zone-id ${hosted_zone_id} --change-batch file://./dnsupdate.json
  3. @TonyFNZ TonyFNZ created this gist Oct 9, 2016.
    35 changes: 35 additions & 0 deletions dnsupdate.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/bin/bash

    hosted_zone_id="<your Route53 hosted zone id>"
    domain_name="<your domain name>"

    # Abort script on any errors
    set -e

    # Get new IP address
    ip_address=`curl http://169.254.169.254/latest/meta-data/public-ipv4`

    # Build temporary file
    cat > ./dnsupdate.json <<EOF
    {
    "Changes": [
    {
    "Action": "UPSERT",
    "ResourceRecordSet": {
    "Name": "$domain_name",
    "Type": "A",
    "TTL": 300,
    "ResourceRecords": [
    {
    "Value": "$ip_address"
    }
    ]
    }
    }
    ]
    }
    EOF

    # Call Route53 to update DNS
    aws route53 change-resource-record-sets --hosted-zone-id $hosted_zone_id --change-batch file://./dnsupdate.json