PassioniInformaticaNetworking

Guida: Configurare DNS dinamico (DDNS) con nsupdate

04/03/2026

Aggiornare automaticamente i record DNS

Con un IP dinamico, il DDNS aggiorna automaticamente il record A del dominio quando l'IP cambia. Utile per accedere al homelab dall'esterno.

1. Con un servizio DDNS (DuckDNS)

# Cron ogni 5 minuti
echo "*/5 * * * * root curl -s \"https://www.duckdns.org/update?domains=miodominio&token=TOKEN\" > /dev/null" > /etc/cron.d/ddns

2. Con nsupdate (DNS proprio)

# Generare chiave TSIG
tsig-keygen -a hmac-sha256 ddns-key > /etc/bind/ddns-key.conf

# Script di aggiornamento
IP=$(curl -s ifconfig.me)
nsupdate -k /etc/bind/ddns-key.conf <<EOFEOF
server ns1.esempio.it
zone esempio.it
update delete home.esempio.it A
update add home.esempio.it 300 A $IP
send
EOFEOF

3. Con Cloudflare API

IP=$(curl -s ifconfig.me)
ZONE_ID="il_tuo_zone_id"
RECORD_ID="il_tuo_record_id"
API_TOKEN="il_tuo_token"

curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  --data "{\"type\":\"A\",\"name\":\"home.esempio.it\",\"content\":\"$IP\",\"ttl\":300}"

4. Verifica

dig +short home.esempio.it
curl ifconfig.me

Il DDNS è essenziale per chi ha IP dinamico e vuole raggiungere il homelab dall'esterno senza dipendere da servizi terzi.

← Guida: Wake-on-LAN — accendere server da remoto Guida: Bonding e teaming — aggregare interfacce... →
← Torna all'elenco