Oct 122010
 

ntp linuxThe Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks.

NTP provides Coordinated Universal Time (UTC). No information about time zones or daylight saving time is transmitted; this information is outside its scope and must be obtained separately. In isolated LANs, NTP could in principle be used to distribute a different time scale (e.g. local zone time), but this is uncommon

NTPDATE

ntpdate is a computer program used to synchronize and set computers’ date and time by polling the Network Time Protocol (NTP) server(s).

The accuracy and reliability of ntpdate depends on the number of servers, the number of polls each time it is run and the interval between runs.



Task 1 : Update system time

ntpdate ntp.ubuntu.com pool.ntp.org

This command will update your linux system time (need root account):

Output:

laptop:~# ntpdate ntp.ubuntu.com pool.ntp.org

11 Oct 22:59:09 ntpdate[12628]: adjust time server 91.189.94.4 offset 0.023347 sec

Task 2 : Check a ntpd server

ntpdate -d ntp1.inrim.it

With the option -d (debug) you can check the reachability of a ntpd server and test a synchronization.

Output:

laptop:~# ntpdate -d ntp1.inrim.it

11 Oct 23:52:07 ntpdate[15798]: ntpdate [email protected] Fri Aug 6 22:49:55 UTC 2010 (1)

Looking for host ntp1.inrim.it and service ntp

host found : ntp1.inrim.it

transmit(193.204.114.232)

receive(193.204.114.232)

transmit(193.204.114.232)

transmit(193.204.114.232)

receive(193.204.114.232)

transmit(193.204.114.232)

transmit(193.204.114.232)

server 193.204.114.232, port 123

stratum 1, precision -18, leap 00, trust 000

refid [CTD], delay 0.06894, dispersion 24.00008

transmitted 4, in filter 4

reference time: d05e057c.f022abbe Mon, Oct 11 2010 23:51:56.938

originate timestamp: d05e0588.eb4fd0e9 Mon, Oct 11 2010 23:52:08.919

transmit timestamp: d05e0588.e929dc72 Mon, Oct 11 2010 23:52:08.910

filter delay: 0.06953 0.00000 0.06894 0.00000

0.00000 0.00000 0.00000 0.00000

filter offset: 0.029989 0.000000 0.030154 0.000000

0.000000 0.000000 0.000000 0.000000

delay 0.06894, dispersion 24.00008

offset 0.030154

11 Oct 23:52:09 ntpdate[15798]: adjust time server 193.204.114.232 offset 0.030154 sec

NTPD

The ntpd program is an operating system daemon that sets and maintains the system time in synchronization with Internet standard time servers. The ntpd program normally operates continuously while adjusting the system time and frequency.

Configuration

Ntpd daemon use (usually) as configuration file /etc/ntp.conf

Installing on ubuntu with the command aptitude install ntp you’ll have a working configuration file and after the install the daemon will be started.

Some explanation on the configuration

# You do need to talk to an NTP server or two (or three).

server ntp.ubuntu.com

The server directive indicate the ntp servers to be used to get an update about time, in your company ask to the peoples in charge of the network, usually routers or other network devices are used as ntp server.

driftfile /var/lib/ntp/ntp.drift

With the directive driftfile you can specify a file to store the frequency correction applied to the local clock to be put it in sync with the UTC, to make faster the synchronization process after a restart of the daemon ntpd.

If this file is defined, the daemon ntpd use as the initial correction frequency of the value found in the file, otherwise use the value 0.

Some useful commands.

Task 3: Check if ntpd is running

ntpq -p

Verify if Network Time Protocol daemon is working properly

Output:

laptop:~# ntpq -p

remote refid st t when poll reach delay offset jitter

==============================================================================

*europium.canoni 193.79.237.14 2 u 50 64 377 71.416 28.190 22.704

If the symbol * left an address, it means that the time is taken by the respective server, if there isn’t any * it means that we’re not aligned with any server.

NTPDATE or NTP ?

ntpdate can be run manually as necessary to set the host clock, or it can be run from the host startup script to set the clock at boot time. This is useful in some cases to set the clock initially before starting the NTP daemon ntpd. It is also possible to run ntpdate from a cron script. However, it is important to note that ntpdate with contrived cron scripts is no substitute for the NTP daemon, which uses sophisticated algorithms to maximize accuracy and reliability while minimizing resource use. Finally, since ntpdate does not discipline the host clock frequency as does ntpd, the accuracy using ntpdate is limited.

HWCLOCK

Hwclock is a program that runs under Linux and sets and queries the Hardware Clock, which is often called the Real Time Clock, RTC, or CMOS clock. This is the program that most Linux systems use to get the time from the Hardware Clock and set the System Time at boot time.

Task 4: Query the hardware clock

hwclock -r

This command show the actual hardware clock of the computer.

Output:
laptop:~# hwclock -r
Tue 12 Oct 2010 12:19:18 AM CEST -0.348773 seconds

Task 5: Adjust both system and hardware clock

ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust

With this command you first synchronize your system clock with ntpdate and than with hwclock –systohc you also sinc the hardwareclock.

Output
laptop:~# ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
12 Oct 00:25:23 ntpdate[17183]: adjust time server 70.86.250.6 offset 0.068321 sec

For more info check also http://ntp.org/

Popular Posts:

Flattr this!

  2 Responses to “Clock management on Linux”

  1. Hi,

    NTPD usually is used on systems, that run 7×24, and are used as source to synchronize other systems. When you do not want to synchronize other systems, OpenNTPD is a very good alternative, because it could easily be configured NOT to listen on port 123. For systems that do not run 7×24, chronyd is a very good alternative, cause it can correct great differences between the time of your local system and a pool of NTP servers, than NTPD can.

  2. Having accurate time on computers is a important to security. A few of my Windows machines over the years have had suck bad time management that I ended up running an NTP server on a Linux machine so those MS-Windows machines could be constantly corrected. Here’s how I did it: http://blog.jdpfu.com/2010/01/16/solved-clock-time-loss-under-windows7-and-vista (non-commercial blog).

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*