Skip to content

Instantly share code, notes, and snippets.

@mims92
Created December 20, 2018 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mims92/1bd2847efd0a8fad8694054979bb150d to your computer and use it in GitHub Desktop.
Save mims92/1bd2847efd0a8fad8694054979bb150d to your computer and use it in GitHub Desktop.
Linux - Bash - Update AWS Route53 DNS with public IP
# Update a DNS record with the public IP
# Use a CRON
# chmod +x update_ip
# Run: source update_ip
#!/bin/bash
current_ip=$CURRENT_IP
new_ip=$(curl -s https://api.ipify.org)
new_ip_validation=$(curl -s https://checkip.amazonaws.com)
if [[ $new_ip == $new_ip_validation && $current_ip != $new_ip ]]
then
aws route53 change-resource-record-sets \
--hosted-zone-id <HOSTEZONEID> \
--change-batch '{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"<DNSRECORDNAME>","Type":"[A|CNAME|...]","TTL":60,"ResourceRecords":[{"Value":"'$new_ip'"}]}}]}'
export CURRENT_IP=$new_ip
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment