How does network time protocol (ntpd) get the right time to my machine?

2

network time protocol (ntpd) sets the time on my system automatically from time servers on the net (or something like that. ;)

What I've always wondered was, how does that work? Everything that comes over the net is in packets that go through multiple hops and delays in a very asynchronous manner, so how does time information from one place get to another with compensation for travel time, etc.?

Joe

Posted 2012-01-04T08:21:49.743

Reputation: 533

Answers

1

The process is quite involved, but note that an NTP sync is a conversation, and as you suspect, it needs to work out the round-trip time in order to effectively sync while taking into consideration how long packets take.

While the client may not know the time accurately when it requests a time update, it does know at least when it sent the packet. The server knows the exact time it receives a packet, plus the exact time it sends a reply. The client knows the intervening time between the time it sent a packet and the receipt of the reply.

So from these numbers it is straightforward to calculate the correct time, provided the delay is consistent across the conversation.

It isn't always consistent of course, which is why multiple servers are generally configured so that errors can be averaged out, along with the client keeping state tracking information so that it can ignore any crazy results.

Wikipedia is a good source for detail.

Paul

Posted 2012-01-04T08:21:49.743

Reputation: 52 173