SDB:Time Synchronization Through the Network

Şuraya atla: kullan, ara


Version: 6.0 - 7.3

Question

How to automatically address a time server under Linux.

Answer

The xntp protocol offers you the possibility to maintain the time (and of course the date) always up to date on your computer. This is particularly important in the case of file and e-mail servers, since otherwise the send date of e-mails or the creation date of files could not be retraced.

A time server must be available on the network (or via the Internet). In the meantime, the ntp protocol is generally used for the time synchronization with a time server. The utilization of netdate is not recommended, since it dependens on the delay of the data on the network.

If your SuSE Linux Version is previous to 7.2, please do not forget to install the security update for NTP before activating it.

Requisites

You need access to a time server and you should not use a firewall filtering the UDP port 123, since this is the port through which the time synchronization occurs. Install the package xntp to have the following programs at your disposal.

One-time synchronization when setting up a dial-in connection

In Germany you could for example synchronize the time in your system with that of the German Institute "Physikalisch-Technischen Bundesanstalt" (reference time in Germany) by entering the following command on a prompt (here written in bold) as root:

earth:~ # ntpdate ntp1.ptb.de
14 Feb 15:09:49 ntpdate[14591]: adjust time server 192.53.103.103 offset
 0.000420 sec

The command also shows you the time difference between your system's and that of the defined time server. If your request is not answered, it probably means that a firewall has stopped your data packets.

Check the following website to find a time server close to you: http://ntp.isc.org/bin/view/Servers/WebHome

You should then start hwclock -w (respectively hwclock -uw, if your computer clock time is set to GMT). Refer to man hwclock for more information.

In order to automatically synchronize the time in your system at every Internet connection, generate the file /etc/ppp/ip-up.local and enter there the commands above.

Time synchronization with a permanent Internet connection

xntpd is a daemon that continuously compares the computer time with that of a time server. xntpd alters your computer's time in very small steps by way of extension or compression of the system time, but always maintaining the synchronization.

Some problems can however occur if the local time differs too strongly (more than 10 minutes) from that of the time server. In this case, start ntpdate and hwclock (see above).

Configuration of XNTPD:
Search for the following line in /etc/rc.config and set the variable to

START_XNTPD=yes

In order to define the server that will be used to synchronize the system, you have to edit the file /etc/ntp.conf. An example of how this file may look like on your system (comment lines are not shown for the sake of legibility) follows:

server ntp1.ptb.de
server ntp2.ptb.de
driftfile /etc/ntp.drift    # path for drift file
logfile   /var/log/ntp      # alternate log file

Execute subsequently SuSEconfig and start the NTP daemon with

rcxntpd start

You can check if the time server is running correctly by using, even as a normal user, the command ntpq after a couple of minutes. Type the command written in bold in the prompt.

earth:~>/usr/sbin/ntpq -c peers
      remote           refid      st t when poll reach   delay   offset  jitter
 ==============================================================================
 *ntp1.ptb.de     .PTB.            1 u   32  128  377   42.371   -0.664   1.349
 +ntp2.ptb.de     .PTB.            1 u  100  128  377   43.329    0.121   3.259
 

The output shows if the synchronization with the time server works (the character in the first column) and how much the packet's delay on the network amounts to.

You can find exhaustive documentation on this subject at /usr/share/doc/packages/xntp/ and via online under www.ntp.org.

Further relevant variables for the time synchronization in /etc/rc.config (see there for comments):

  • TIMEZONE - in central Europe MET.
  • GMT - defines if the computer clock is set locally or to GMT.

You will find additional public NTP servers at the website http://ntp.isc.org/bin/view/Servers/WebHome

SDB:Setting the clock to GMT (Greenwich Mean Time)


<keyword>timeserver,time,xntpd,netdate</keyword>