NTP time server

NTPDATE

If we want to update the date of our serveur from time to time, we type the following:

$ntpdate {a time server}

Note: we must stop the process ntpd if it is running, we can do that with:

# /etc/init.d/ntp stop
or
# /etc/init.d/ntpd stop

If we must do a scheduled task which executes ntpdate (ntp linux which syncrhonizes with a Windows server time for example), we can add the following line in crontab ; it will be executed every day:

0 0 * * * /usr/sbin/ntpdate NAME_OR_IP_TIME_SERVER

 

NTP

If ntp isn’t installed, we can do that with:

# apt-get install ntp

Then we edit the file /etc/ntp.conf
We can comment the lines of default servers or/and add new seervers:

server {SERVER NAME}

We restart NTP with:

# /etc/init.d/ntpd start
or
# /etc/init.d/ntp start

We can see if the configuration is good with:

$ ntpq -p

or

$ ntpdc -p
user$ ntpdc -p
     remote           local      st poll reach  delay   offset    disp
=======================================================================
=europium.canoni 91.121.84.178    2 1024  377 0.00427  0.000199 0.13666
=ks2985.kimsufi. 91.121.84.178    3 1024  377 0.00429  0.002239 0.12180
*po-95462.fropli 91.121.84.178    2 1024  377 0.00427  0.000600 0.12177
=time.digimedia. 91.121.84.178    2 1024  377 0.00061 -0.002265 0.13666
=vr6.zeroi.com   91.121.84.178    2 1024  377 0.01297  0.000391 0.12180
user@ks27336:~$

 

Notes

It happens that ntpq -p doesn’t work and sends an error:

[root@serveur5.openlog.it ~]# ntpq -p
Name or service not known

If it happens, it’s due to the lack of a localhost line in the file /etc/hosts . In that case, we must add a line which matches 127.0.0.1 with localhost. As in our example, the mention of localhost could be made by putting the localhost word at the end of an existent line which concerns 127.0.0.1.

127.0.0.1       serveur5.openlog.it localhost

 

Leave a Reply

Your email address will not be published. Required fields are marked *