Created
December 20, 2018 09:43
-
-
Save mims92/1bd2847efd0a8fad8694054979bb150d to your computer and use it in GitHub Desktop.
Linux - Bash - Update AWS Route53 DNS with public IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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