Skip to content

Instantly share code, notes, and snippets.

@grahamc

grahamc/dns.sh Secret

Created December 9, 2019 02:14
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 grahamc/dba13660a088431857d7e5461b0ee2ff to your computer and use it in GitHub Desktop.
Save grahamc/dba13660a088431857d7e5461b0ee2ff to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eux
# More advanced options below
# The Time-To-Live of this recordset
dns() {
RECORD=$1
TYPE=$2
IP=$3
TTL=300
# Fill a temp file with valid JSON
TMPFILE=$(mktemp /tmp/temporary-file.XXXXXXXX)
cat > ${TMPFILE} << EOF
{
"Changes":[
{
"Action":"UPSERT",
"ResourceRecordSet":{
"ResourceRecords":[
{
"Value":"$IP"
}
],
"Name":"$RECORD",
"Type":"$TYPE",
"TTL":$TTL
}
}
]
}
EOF
# Update the Hosted Zone record
aws route53 change-resource-record-sets \
--hosted-zone-id $ZONEID \
--change-batch file://"$TMPFILE"
echo ""
# Clean up
rm $TMPFILE
}
dns "$(hostname).wg.gsc.io" "A" "$(ip --json addr show dev wg0 \
| jq -r '.[] | .addr_info[] | select(.family == "inet") | .local')"
dns "$(hostname).gsc.io" "A" "$(curl https://ipv4.icanhazip.com)"
dns "$(hostname).gsc.io" "AAAA" "$(curl https://ipv6.icanhazip.com)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment