Created
December 29, 2022 02:09
-
-
Save wiredmax/c31487b78abbc34c1874cb856ab0555e to your computer and use it in GitHub Desktop.
Dynamics DNS script for Route53
This file contains hidden or 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
#!/bin/sh | |
IP="$(curl -s https://checkip.amazonaws.com/)" | |
ZONEID="AWSZ0N3IDH3R3" | |
DOMAIN="subdomain.example.com" | |
DNS="$(mktemp)" | |
cat > "${DNS}" <<EOF | |
{ | |
"Comment": "DDNS update", | |
"Changes": [ | |
{ | |
"Action": "UPSERT", | |
"ResourceRecordSet": { | |
"ResourceRecords": [ | |
{"Value": "${IP}"} | |
], | |
"Name": "${DOMAIN}", | |
"Type": "A", | |
"TTL": 300 | |
} | |
} | |
] | |
} | |
EOF | |
DNSIP="$(dig +short ${DOMAIN})" | |
ROUTE53IP="$(aws route53 list-resource-record-sets --hosted-zone-id ${ZONEID} --query "ResourceRecordSets[?Name == '${DOMAIN}.']" | jq -r '.[0].ResourceRecords[0].Value')" | |
echo Current IP: $IP | |
echo DNS IP: $DNSIP | |
echo Route 53 IP: $ROUTE53IP | |
if [ "$IP" = "$ROUTE53IP" ]; | |
then | |
echo IPs match, nothing to do | |
else | |
echo IPs differ, need to update DNS | |
aws route53 change-resource-record-sets --hosted-zone-id "/hostedzone/${ZONEID}" --change-batch "file://${DNS}" | |
fi | |
rm "${DNS}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment