Sincronizazione con un server NTP esterno
Per aggiornare manualmente l'ora di sistema (e ad ogni boot, datoc he è uno script init.d), si può usare:
ntpdate pool.ntp.org
Se il sistema non è dotato di una connessione stabile a internet, schedulare una volta al giorno il comando.
Se invece si vuole mantenere aggiornato costantemente l'orario, è meglio usare il demone ntp.
Installazione pacchetti
Installare i pacchetti base:
apt-get install ntpdate ntp-simple
Aggiornare manualmente l'orario
/et/init.d/ntpdate restart
Impostazione dei server con cui sincronizzarsi
vi /etc/ntp.conf ... server it.pool.ntp.org server ch.pool.ntp.org server europe.pool.ntp.org ...
Riavviare il demone:
/etc/init.d/ntp-server restart
Verifica della sincornizzazione
Verificare che la configurazione sia attiva:
ntpq -p
Verranno elencati i server. Dopo alcuni minuti (a volte anche 30), si dovrebbe avere:
remote refid st t when poll reach delay offset jitter ============================================================================== +magma.woody.ch 217.150.242.8 2 u 109 128 377 30.832 11.660 128.525 +ip-26-10.sn1.eu 130.149.17.8 2 u 98 128 377 80.448 21.208 41.992 *adsl.remco.org .PG0A. 1 u 20 128 377 45.985 2.632 101.114 LOCAL(0) LOCAL(0) 13 l 16 64 377 0.000 0.000 0.001
il "+" e "*" significano che i server sono stati contatti e ci si è sincronizzati.
Per vedere se i server sono raggiungibili:
ntpq -c as ind assID status conf reach auth condition last_event cnt =========================================================== 1 61876 9414 yes yes none candidat reachable 1 2 61877 9414 yes yes none candidat reachable 1 3 61878 9614 yes yes none sys.peer reachable 1 4 61879 9014 yes yes none reject reachable 1
Utilizo come ntp server interno
La configurazione di default permette di utiliare un server così configurato anche per settare l'ora dei client interni.
ATTENZIONE: affinchè il server sia utilizzabile, deve essersi già aggiornato con un altro, cioè deve esserci l'asterisco. Se si tenta di aggiornare un client interno prima che il server abbia contatto almeno un suo server, si riceve l'errore:
# ntpdate fire 26 Jul 14:44:28 ntpdate[21881]: no server suitable for synchronization found
Infatti, debuggando, si capisce che:
ntpdate -d fire
26 Jul 14:44:33 ntpdate[21883]: ntpdate 4.2.0a@1:4.2.0a+stable-2-r Sun Jan 9 16:13:28 CET 2005 (1)
transmit(192.168.0.254)
receive(192.168.0.254)
transmit(192.168.0.254)
receive(192.168.0.254)
transmit(192.168.0.254)
receive(192.168.0.254)
transmit(192.168.0.254)
receive(192.168.0.254)
transmit(192.168.0.254)
192.168.0.254: Server dropped: strata too high
server 192.168.0.254, port 123
stratum 16, precision -20, leap 11, trust 000
refid [192.168.0.254], delay 0.02580, dispersion 0.00000
transmitted 4, in filter 4
reference time: 00000000.00000000 Thu, Feb 7 2036 7:28:16.000
originate timestamp: c690aeb1.85cdc443 Tue, Jul 26 2005 14:44:33.522
transmit timestamp: c690aeb1.85c17225 Tue, Jul 26 2005 14:44:33.522
filter delay: 0.02583 0.02580 0.02580 0.02582
0.00000 0.00000 0.00000 0.00000
filter offset: 0.000071 0.000063 0.000060 0.000052
0.000000 0.000000 0.000000 0.000000
delay 0.02580, dispersion 0.00000
offset 0.000063
Cioè:
192.168.0.254: Server dropped: strata too high
Il server a cui si stà facendo riferimento non è aggiornato.
Lo stratum è il livello di affidabilità.
Per aggiornare un client con ntpd installato, è sufficente inserire in /etc/ntpd.conf il nome del server interno, avendo cura di aprire su quest'ultimo la porta UDP 123 in INPUT ed OUTPUT
TODO: authenticazione public key
Link Utili
Using NTP to Maintain You System Clock