Raspberry Pi como servidor de hora con ntp - Electronik-Pro, Informatica, Noticas,Wordpress,Facebook,Hacking,Programas,Hosting,Dominios

NTP (Network Time Protocol) es un protocolo IP para mantener sincronizados los relojes de diferentes equipos informáticos que escucha en el puerto 123.

NTP define una jerarquía de estratos de reloj, donde:
  • Los sistemas de estrato 1 se encuentran sincronizados con un reloj externo como un reloj atómico o un reloj GPS.
  • Los sistemas de estrato 2 se encuentran sincronizados con sistemas de estrato 1.
  • Y así sucesivamente.
En este post vamos a ver cómo configurar:
  • Un servidor ntp en nuestra Raspberry Pi.
  • Un cliente ntp Debian de nuestra red.
Configurar un servidor ntp.-
En Debian utilizamos el demonio ntp tanto para el cliente como para el servidor. Disponer de este demonio es muy sencillo. Tan sólo tenemos que instalar el paquete ntp:
# apt-get install ntp
Una vez instalado, vamos a configurarlo. Para ello, paramos el servidor ntp:
# service ntp stop
Y editamos el fichero de configuración:
# nano /etc/ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool:
server hora.roa.es iburst
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

# Local clock para que continue sirviendo su hora aunque no tenga acceso a internet
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details. The web page
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines. Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient
Para que funcione, tan sólo tenéis que configurar los servidores de hora a los que vuestro servidor va a consultar. Podéis obtener una lista de servidores de hora en la siguiente página: http://www.pool.ntp.org/

Una vez configurado, arrancamos de nuevo el servicio:
# service ntp start

Para comprobar  que el servicio está bien configurado y los servidores de hora responden, ejecutamos:
root@raspberrypi:~# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
hora.roa.es .INIT. 16 u - 64 0 0.000 0.000 0.001
147.83.123.133 .INIT. 16 u - 64 0 0.000 0.000 0.001
guti.uc3m.es 130.206.3.166 2 u 1 64 1 64.854 0.273 0.182
i2t15.i2t.ehu.e .GPS. 1 u 2 64 1 86.872 8.485 0.001
mx.saviacr.com 130.206.3.166 2 u 1 64 1 115.776 7.900 0.001
*LOCAL(0) .LOCL. 10 l - 64 1 0.000 0.000 0.001
Como podéis ver en la salida anterior, el servidor funciona y puede contactar con los servidores de hora que le hemos configurado.

Configurar un cliente ntp.-
El siguiente paso será configurar un cliente de nuestra red. Para ello:
Instalamos el paquete ntp en el cliente:
# apt-get install ntp
Editamos el fichero ntp.conf del cliente y le añadimos la siguiente línea:
server raspberrypi.local iburst
Asumimos que tenemos instalado avahi (para poder utilizar el nombre de máquina raspberrypi.local)y que el nombre de host de nuestra Raspberry es: raspberrypi.

Por último, reiniciamos el demonio ntp en el cliente:
# service ntp restart
Una vez reiniciado, ejecutamos en el cliente:
ldap:~# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
raspberrypi.loc 150.214.94.5 2 u - 64 1 0.735 -1.966 0.001
fw1.engloba.net .INIT. 16 u - 64 0 0.000 0.000 0.001
ns1.indaloweb.n .INIT. 16 u - 64 0 0.000 0.000 0.001
evl1900860-pip. .INIT. 16 u - 64 0 0.000 0.000 0.001
guti.uc3m.es .INIT. 16 u - 64 0 0.000 0.000 0.001

Como podéis comprobar en la primera línea de los resultados, nuestra Raspberry Pi está sirviendo su hora.
Publicado por primera vez en http://enavas.blogspot.com.es

0 comentarios:

Publicar un comentario

 
Top