Skip to content

Instantly share code, notes, and snippets.

@Zash
Created May 15, 2023 16:53
Show Gist options
  • Save Zash/6a84139173a6f098b6f69c7353d28c73 to your computer and use it in GitHub Desktop.
Save Zash/6a84139173a6f098b6f69c7353d28c73 to your computer and use it in GitHub Desktop.
Update SSHFP records
#!/bin/bash
set -eo pipefail
ZONE="$(hostname -d)"
FQDN="$(hostname -f)"
UPDATES="$(mktemp --suffix .nsupdate)"
trap 'rm -- "$UPDATES"' EXIT
{
echo "server $(dig +noall +short "$ZONE" soa | cut -d' ' -f1)"
echo "zone $ZONE"
echo "ttl 3600"
echo "del $FQDN IN SSHFP"
ssh-keygen -r "$FQDN" | sed 's/^/add /'
echo "show"
echo "send"
echo "answer"
} > "$UPDATES"
if [ -f "$HOME/.config/nsupdate/$ZONE.key" ]; then
nsupdate -k "$HOME/.config/nsupdate/$ZONE.key" "$UPDATES"
else
cat "$UPDATES"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment