Network Time Protocol (NTP) is a network protocol for synchronizing clock between computers by packet switching, with a variable latency across data networks. NTP is one of the oldest Internet protocols in operation. It worked even before 1985. NTP allows network devices to synchronize their time settings with an NTP server. A group of NTP customers who get time and date information from a single source will have more consistent time settings.
Much of the technology used on a large scale depends on a precise measurement of time. The Global Positioning System (GPS) uses messages that contain time information from at least 24 satellites orbiting the Earth. Many other medical, military and astronomical applications rely heavily on the degree of precision with which they measure time. Most of the atomic clocks use the oscillation of the energy states of the Cesium 133 radioactive atom. The International System of Units (SI) defines the second as the duration of 9 192 631 770 oscillations of the Cesium atom when subjected to an electromagnetic field.
Even personal devices need a more accurate record of the passage of time. Aspects such as time zones or summertime/wintertime variations are complicated, and therefore operating systems make these conversions exclusively for the user’s comfort. Actually, electronic devices use UTC.
POSIX-compatible operating systems (Unix, Linux, etc.) measure time as the number of seconds that elapsed since January 1, 1970 at 00:00 UTC, also called the Unix epoch. This value is called the Unix timestamp, and can be obtained with the command +% s.
The way a personal computer keeps track of the passage of time is quite imprecise and, without external intervention, its clock may suffer significant gaps in real time. To solve this problem, modern operating systems use various mechanisms to compensate the problem, and the most popular of them is the Network Time Protocol (NTP). NTP is based on a hierarchy of servers called clock sources.
The closest NTP servers to the atomic clock are called layer 0, and provide sync services only to layer 1 servers. Layer 1 servers synchronize layer 2 servers, and so on for an arbitrary number of layers. Most NTP public servers are layer 2 or higher.
The protocol measures the time spent by packages on the route between the server and the client, adjusting the internal clock based on this delay. Popular Linux distributions use two time synchronization mechanisms with NTP: ntpdate and ntpd. The first one is used for a single sync with a NTP server and is included in most distributions:
$ ntpdate pool.ntp.org
The NTP daemon (ntpd), monitors the system clock permanently and makes continuously fine adjustments. Installing ntpd in Ubuntu is very easy: $ sudo apt-get install ntp It uses the ntp.ubuntu.com server for sync by default, but can be configured to choose other servers as well (geographically closer, for example). The configuration file is /etc/ntp.conf and contains many options, but the most important are the server addresses:
server ntp.ubuntu.com
server pool.ntp.org
When the NTP daemon initializes, it contacts all the declared servers, compares the answers to each other, and chooses as the primary source, the most accurate server.
The NTP Pool project (pool.ntp.org) offers a large number of NTP servers worldwide. These are managed by volunteers who offer their own system resources to provide millions of free synchronization services.