Skip to content

Instantly share code, notes, and snippets.

@DasSkelett
Created March 12, 2025 22:23
Show Gist options
  • Save DasSkelett/1c5a321649504568c4e1f501cd8d9473 to your computer and use it in GitHub Desktop.
Save DasSkelett/1c5a321649504568c4e1f501cd8d9473 to your computer and use it in GitHub Desktop.
Dynamic DNS records for Freifunk nodes from meshviewer.json
#!/bin/bash
set -ex
# prefix of node hostnames to filter for
PREFIX=""
# TSIG key name
KEYNAME=""
# base64 encoded TSIG key
KEY=""
# base domain / zone where records should be added
BASEDOMAIN=""
# address of authoritative DNS server for the above specified zone
DNSSERVER=""
NODES=$(curl -sSL https://map.ffmuc.net/data/meshviewer.json | jq '[.nodes[] | select(.hostname | startswith("$PREFIX")) | pick(.hostname, .node_id, .addresses)]')
cmd="
server $DNSSERVER 53
zone $BASEDOMAIN
"
#echo "$NODES" | jq -c '.[]' | while read -r node
while read -r node
do
hostname=$(echo "$node" | jq -r '.hostname')
id=$(echo "$node" | jq -r '.node_id')
ip0=$(echo "$node" | jq -r '.addresses[0]')
ip1=$(echo "$node" | jq -r '.addresses[1]')
cmd+="update delete $hostname.$BASEDOMAIN. AAAA"$'\n'
cmd+="update delete $id.$BASEDOMAIN. AAAA"$'\n'
cmd+="update add $hostname.$BASEDOMAIN. 300 AAAA $ip0"$'\n'
cmd+="update add $hostname.$BASEDOMAIN. 300 AAAA $ip1"$'\n'
cmd+="update add $id.$BASEDOMAIN. 300 AAAA $ip0"$'\n'
cmd+="update add $id.$BASEDOMAIN. 300 AAAA $ip1"$'\n'
done < <(echo "$NODES" | jq -c '.[]')
cmd+="key hmac-sha512:$KEYNAME $KEY"$'\nsend\n'
echo "$cmd" | nsupdate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment