Creazione di un sistema DDNS con Bind: Difference between revisions
Jump to navigation
Jump to search
| (4 intermediate revisions by the same user not shown) | |||
| Line 16: | Line 16: | ||
cd | cd | ||
dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -n USER email.example.com. | dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -n USER email.example.com. | ||
* '''ATTENZIONE A GENERARE LA CHIAVE CON IL NOME CORRETTO, CHE ANDRÀ SEMPRE UTILIZZATO. LA CHIAVE CONTIENE ANCHE IL NOME DELLO USER, E QUANDO SI FA RIFERIMENTO ALLA CHIAVE STESSA NELLA CONFIGURAZIONE DI BIND, OCCORRE UTILIZZARE IL NOME ESATTO CON CUI È GENERATA LA CHIAVE''' | |||
* Questo genera due files: | * Questo genera due files: | ||
| Line 34: | Line 36: | ||
<pre> | <pre> | ||
cat | sudo tee /etc/bind/ddns-keys.conf > /dev/null <<EOFile | cat | sudo tee -a /etc/bind/ddns-keys.conf > /dev/null <<EOFile | ||
key email.example.com. { | key email.example.com. { | ||
algorithm HMAC-MD5; | algorithm HMAC-MD5; | ||
| Line 139: | Line 141: | ||
test.example.com has address 1.2.3.4 | test.example.com has address 1.2.3.4 | ||
</pre> | </pre> | ||
* Se | |||
:sul client si ottiene un errore tipo | |||
BADKEY | |||
:sul server si ottiene un errore del tipo | |||
request has invalid signature: TSIG email.example.com.: tsig verify failure (BADKEY) | |||
:allora significa che o la chiave è sbagliata o il nome utente della chiave è sbagliato. | |||
==Note relative alle zone dinamiche== | ==Note relative alle zone dinamiche== | ||
| Line 228: | Line 239: | ||
*[https://www.andrewzammit.com/blog/reload-dns-zone-with-bind9-and-rndc/ Reload DNS Zone with Bind9 and rndc | put things down] | *[https://www.andrewzammit.com/blog/reload-dns-zone-with-bind9-and-rndc/ Reload DNS Zone with Bind9 and rndc | put things down] | ||
*[https://bugs.launchpad.net/ubuntu/+source/bind9/+bug/963368 Bug #963368 “dnssec-keygen takes forever to generate a keyfile” : Bugs : bind9 package : Ubuntu] | *[https://bugs.launchpad.net/ubuntu/+source/bind9/+bug/963368 Bug #963368 “dnssec-keygen takes forever to generate a keyfile” : Bugs : bind9 package : Ubuntu] | ||
*[https://blog.hqcodeshop.fi/archives/76-Doing-secure-dynamic-DNS-updates-with-BIND.html Doing secure dynamic DNS updates with BIND - Hacker's ramblings] | |||
*[http://serverfault.com/questions/531112/bind-9s-nsupdate-dyndns-update-gives-tsig-verify-failure-badkey linux - BIND 9's nsupdate dyndns update gives: "tsig verify failure (BADKEY)" - Server Fault] | |||
*[http://jpmens.net/2010/09/28/performing-dynamic-dns-updates-on-your-dns/ Jan-Piet Mens :: Performing dynamic DNS updates on your DNS] | |||
Latest revision as of 16:09, 4 March 2016
E' possibile creare un sistema DDNS di aggiornamento dinamico dei nomi DNS con Bind 9.x, usando l'utility nsupdate da linux.
Preparazione del Server
- Il server deve essere già configurato e funzionante con la gestione completa di una zona.
Generazione della chiave di aggiornamento
- Questa chiave permetterà ai client di aggiornare il nome DNS sul server.
- Installazione pacchetti necessari:
sudo apt-get install dnsutils bind9utils
- Si genera la chiave per un utente fittizio, usando un indirizzo email fittizio tipo email@example.com:
cd dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -n USER email.example.com.
- ATTENZIONE A GENERARE LA CHIAVE CON IL NOME CORRETTO, CHE ANDRÀ SEMPRE UTILIZZATO. LA CHIAVE CONTIENE ANCHE IL NOME DELLO USER, E QUANDO SI FA RIFERIMENTO ALLA CHIAVE STESSA NELLA CONFIGURAZIONE DI BIND, OCCORRE UTILIZZARE IL NOME ESATTO CON CUI È GENERATA LA CHIAVE
- Questo genera due files:
Kemail.example.com.+157+31772.key Kemail.example.com.+157+31772.private
- Queste due chiavi andranno poi SPOSTATE poi sul client. I files non sono necessari sul server.
- Per stampare la chiave:
cat Kemail.example.com.+157+31772.private | grep Key | cut -b6-
rD3UJquI5r1Rvd9MblnoMCc7uS9ZYgC49Z/fgS0QwGaLBMHgPPdjYZVAIqpZGHAg+NDulKhJ2d5Sf4na+Tkzng=
Configurazione della chiave sul DNS Server
- Creazione del file di configurazione delle chiavi:
cat | sudo tee -a /etc/bind/ddns-keys.conf > /dev/null <<EOFile
key email.example.com. {
algorithm HMAC-MD5;
secret "rD3UJquI5r1Rvd9MblnoMCc7uS9ZYgC49Z/fgS0QwGaLBMHgPPdjYZVAIqpZGHAg+NDulKhJ2d5Sf4na+Tkzng==";
};
EOFile
sudo chown root:bind /etc/bind/ddns-keys.conf
sudo chmod 640 /etc/bind/ddns-keys.conf
- Inclusione del file nella configurazione di bind:
sudoedit /etc/bind/named.conf.local
include "/etc/bind/ddns-keys.conf";
- Riavvio di bind
sudo sudo /etc/init.d/bind9 restart
Configurazione della zona DNS sul server DNS
- Anche la zona va configurata per accettare le modifiche tramite la chiave
- Editare il file contenete i dati della zona, ad esempio:
sudoedit /etc/bind/named.conf.publiczones
zone "example.com" {
type master;
file "/etc/bind/example.com.db";
};
- Aggiungere le regole di update nella forma:
update-policy {
grant <key> <type> <zone> <record-types>;
};
- Dove
- <key> è il nome della chiave a cui si vuole dare il privilegio, nel nostro caso email.example.com.
- <type> è il contesto in cui si esprime la regola: 'name' per un solo nome dns o 'subdomain' per un intero dominio
- <zone/name> è il nome DNS o il sottodominio DNS seguiti da punto che si vogliono aggiornare , ad esempio example.com. o test.example.com.
- <record-types> è l'elenco separato da spazi dei tipi di record che si possono aggiornare, ad esempio A CNAME TXT
- Ad esempio, per permettere alla nostra key email.exaple.com. di poter aggiornare il singolo name test.example.com. come record-types A o TXT:
zone "example.com" {
update-policy {
grant email.example.com name test.example.com. A TXT;
};
type master;
file "/etc/bind/example.com.db";
};
- Restartare Bind
sudo /etc/init.d/bind9 restart
- Dato che a seguito di un update, bind creerà il jounrla file /etc/bind/example.com.db.jnl , assicurarsi che lo user bind possa scrivere nella stessa directory dove sono specificati i file di zona, ad esempio
sudo chown :bind /etc/bind sudo chmod g+w /etc/bind
Test di aggiornamento
- Proviamo ora ad aggiornare il record test.example.com sul server dns locale appena configurato:
cd
nsupdate -k Kemail.example.com.+157+31772.private -v <<EOFile
server ns1.example.com
zone example.com
update delete ${NAME}.example.com. A
update add ${NAME}.example.com. 60 A 1.2.3.4
show
send
EOFile
- Se tutto è configurato a dovere, otterremo:
Outgoing update query: ;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id: 0 ;; flags:; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0 ;; ZONE SECTION: ;example.com. IN SOA ;; UPDATE SECTION: test.example.com. 0 ANY A test.example.com. 60 IN A 1.2.3.4
- Verificare:
host test.example.com localhost
Using domain server: Name: localhost Address: 127.0.0.1#53 Aliases: test.example.com has address 1.2.3.4
- Se
- sul client si ottiene un errore tipo
BADKEY
- sul server si ottiene un errore del tipo
request has invalid signature: TSIG email.example.com.: tsig verify failure (BADKEY)
- allora significa che o la chiave è sbagliata o il nome utente della chiave è sbagliato.
Note relative alle zone dinamiche
- ATTENZIONE: QUANDO SI USA L'UPDATE DINAMICO DI UNA ZONA, NON EDITARE MAI DIRETTAMENTE IL FILE DI ZONA STESSO, MA SEGUIRE LA PROCEDURA SEGUENTE
- Quando si modificano dei record dinamicamente, le modifiche non sono contenute nel file di zona testuale, ma bensì nel journal, il cui contenuto è visionabile con
named-journalprint /etc/bind/example.com.db.jnl
add test.example.com. 60 IN A 1.2.3.4
- Se si vuole modificare il fiel di zona, ANCHE PER RECORD NON GESTITI DINAMICAMENTE, bisogna prima trasferire queste modifica nel file di zona, tramite un freeze della zona stessa. Per comodità, effettuiamo un freeze di tutte le zone
sudo rndc -k /etc/bind/rndc.key -s localhost freeze
- Questo comando sposterà tutte le modifiche dai journal nei file di zona stessi, ELIMINANDO i file di journal
- Terminate le modifiche, si riabilita l'aggiornamento dinamico della zona, ed al primo update, verrà ricreato il journal
sudo rndc -k /etc/bind/rndc.key -s localhost thaw
- Se si ricevono errori durante il freeze o thaw, verificare i diritti sulla diretcory di zona e che non ci siano errori nei files di descrizione delle zone
- ANCHE QUANDO SI FA UN RELOAD DI BIND, È NECESSARIO FARE UN FREEZE, RELOAD, THAW
Configurazione del Client
Installazione delle chiavi
Cancellare le chiavi dal Server e copiarle sul client in /etc/bind/ddns-keys:
sudo mkdir -p /etc/bind/ddns-keys sudo mv Kemail.example.com.+157+31772.key /etc/bind/ddns-keys sudo mv Kemail.example.com.+157+31772.private /etc/bind/ddns-keys sudo chown root:bind /etc/bind/ddns-keys/* sudo chmod 640 /etc/bind/ddns-keys/*
Configurazione dello script di aggiornamento per una connessione ppp
Creaiamo lo script che ad ogni collegamento di PPP, aggiorni il nome DNS:
cat | sudo tee /etc/ppp/ip-up.d/05-sendipaddress > /dev/null <<'EOFscript'
#!/bin/sh -e
NAME=$(hostname | cut -b5-)
nsupdate -k /etc/bind/ddns-keys/Kemail.example.com.+157+31772.private -v <<EOFile
server ns1.example.com
zone example.com
update delete ${NAME}.example.com. A
update add ${NAME}.example.com. 60 A $PPP_LOCAL
show
send
EOFscript
chmod +x /etc/ppp/ip-up.d/05-sendipaddress
Provare ad eseguirlo, (NON TRAMITE SUDO PERCHE' NON PASSA LE VARIABILI DI AMBIENTE, quindi cambiando le permission delle chiavi) e se tutto è corretto, il nome verrà aggiornato al valore indicato:
sudo chmod a+r /etc/bind/ddns-keys/*
PPP_LOCAL=1.2.3.4 /etc/ppp/ip-up.d/05-sendipaddress
Outgoing update query: ;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id: 0 ;; flags: ; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0 ;; UPDATE SECTION: test.example.com. 0 ANY A test.example.com. 60 IN A 1.2.3.4
Risistemare le permission delle chiavi:
sudo chmod 640 /etc/bind/ddns-keys/*
Testare:
host test.example.com
test.example.com has address 1.2.3.4
- Script di scollegamento: se esistesse la possibilità di eseguire uno script di PRE-DOWN, si potrebbe fare un delete del nome dns, ma non esiste ...
Riferimenti
- nsupdate: Painless Dynamic DNS
- nsupdate: Painless Dynamic DNS Painless DDNS part 2: the server
- Working with a journal-ized bind zone - AOssama
- Reload DNS Zone with Bind9 and rndc | put things down
- Bug #963368 “dnssec-keygen takes forever to generate a keyfile” : Bugs : bind9 package : Ubuntu
- Doing secure dynamic DNS updates with BIND - Hacker's ramblings
- linux - BIND 9's nsupdate dyndns update gives: "tsig verify failure (BADKEY)" - Server Fault
- Jan-Piet Mens :: Performing dynamic DNS updates on your DNS