by Girish Venkatachalam
Girish Venkatachalam is a UNIX hacker with more than a decade of
networking and crypto programming experience.
His hobbies include yoga,cycling, cooking and he runs his own
business. Details here:
It is ridiculous that a computer that we buy for several hundred dollars
cannot be as accurate as a watch that be bought for less than 10$.
That does not have to be the case once you read and understand this article.
Network Time Protocol described in RFC1305 in enough detail and chatty
language is the trick behind keeping computers in sync with the most
accurate time sources on the plant - atomic clocks on board satellites
that are used by GPS gear.
GPS will not even work without sub millisecond accuracy but our computer
can be oblivious of time and still do all its work. This is true of even
servers including mail servers or web servers.
But it is backward to not have accurate time on your machines.
Especially when you can easily get this for free on the Internet.
All you have to do is run the ntp daemon. There are several watered down
protocols called daytime and rdate that can help too. For instance, all
you have to do is type this as root:
# rdate ptbtime1.ptb.de
That is all there is to it to fix a clock that might have been off by
even days. Who knows?
There are also Windows software that can do the same thing. Please
google for "free SNTP client". You know what SNTP will stand for if you
know NTP. It is Simple Network Time Protocol.
I started my career in Novell in 1998 with a protocol converter project
that would make the Netware world talk to the UNIX world. I wrote a
program that would act as a bridge for time and translate the
proprietary TimeSync format with the NTP time format.
My project suddenly assumed a lot of importance when their Netware
server experienced severe time lag due to some driver eating up the
I think mostly due to corporate politics than anything else, the driver
team refused to fix the issue. And the issue was in our hands. I did the
right thing by ignoring the timer interrupts and taking time from the
hardware clock on the PC. The RTC that is found on most computers.
My work was appreciated in the form of an award though what I did was
clearly wrong. The real fix should have been on the driver. But this
should tell you something about the commercial corporate world. They put
the cart before the horse and see things upside down.
Let us save our crib about the silly commercial world and get back to
the wonderful world of UNIX and open source geeks. Before that I wish to
point out that my work also was critical in signing a 5 million dollar
deal with British Telecom long ago. They had two networks firewalled
from one another and time had to be synchronized between them. I
suggested using NTP since the Internet has several freely available
public NTP stratum 1 servers.
By the way, Novell had a dying need for accurate time due to directory
synchronization. NDS which was a precursor to LDAP needed time to be in
But as I said in the beginning, it is ridiculous and somewhat inane not
to have your computers in sync with the accurate time. You might not
need microsecond accuracy but asking for millisecond accuracy is not too
much. Come on, computers are deterministic and this is what they are
There is a command called ntpdate which works similar to
rdate on the surface but underneath it is very different.
# ntpdate ptbtime1.ptb.de
I should also talk about the innards just to pique the curiosity of
detail oriented peoples. NTP uses source port and destination port UDP
123 for its time query packets. And NTP works in unicast or multicast
mode. I have never bothered with multicast configurations. NTP does add
traffic to the network but in today's terms it is negligible and
NTP comes with a clock filtering algorithm, a clock selection algorithm
when faced with multiple sources that offer different times and it also
has protections against malicious tampering by using cryptographic keys.
stratum 1 servers are supposed to be the most accurate followed by
stratum 2 or stratum 3 depending on how far away they are from accurate
time sources like the atomic clocks. I believe that OpenBSD comes with
time sensors that can obtain time through long wave radio and adjust
their clocks. This is not available in the entire developed world.
The way NTP does its work is by exchanging UTC time format in the number
of seconds that elapsed from
1900 1970 in a 64 bit field. 32 bits of seconds
and 32 bits of subsecond data. You have leap years, leap seconds and
what not. And the counter will overflow in 2038. People are predicting
the world to end by then...that we will have a revisit of the y2k
problem. Do you care?
Here is the equation for clock correction.
time difference = time at destination - time at source
Time queries are sent as
simple UDP packets with time fields on them. The time fields are
used to arrive at the correction factor. The computer never sets its
clock back. So don't be surprised if your computer does not go back in
time. And for NTP to work, the packet latency in the forward and reverse
paths have to be the same. Otherwise you won't get accurate time. Think
about it, you will know why this is necessary.
Got something to add? Send me email.
Increase ad revenue 50-250% with Ezoic
More Articles by Girish Venkatachalam
© 2009-11-07 Girish Venkatachalam