TCP/IP Protocol: Network Time Protocol (NTP)

Discussion in 'Linux Networking' started by Jarret W. Buse, Nov 13, 2013.

  1. Jarret W. Buse

    Jarret W. Buse Active Member Staff Writer

    Messages:
    167
    Likes Received:
    239
    Trophy Points:
    43
    TCP/IP Protocol: Network Time Protocol (NTP)

    The Network Time Protocol is one of the oldest protocols in the TCP/IP Protocol Suite. The protocol was designed in 1985 by David L. Mills of the University of Delaware. As of June 2010, NTP has a current version of 4, sometimes referred to as NTPv4.

    Time was set according to Greenwich Mean Time (GMT), but changed in 1963 to the Coordinated Universal Time (UTC). UTC was created by the International Radio Consultative Committee. An update was done in 1972 to deal with Leap Seconds.

    NOTE: Leap Seconds are used to help maintain the time due to the variance of the Earth’s rotation. Since the adoption in 1972, there have been 25 Leap Seconds added. One such addition occurred on June 30, 2012 at 23:59:60 UTC. When a Leap Second is inserted, the second is placed on a specified day. The exact time the Leap Second occurs, is between 12:59:59 and 00:00:00 on the specified day. When the Leap Second occurs the time will show 12:59:60 and then flip over to 00:00:00. Leap Seconds are added either on June 30 or December 31. Leap Seconds cannot be predicted too far in advance, so the usual time for a Leap Second is announced eight weeks in advance. There is a means of accounting for the Earth to speed up, but this has not happened.

    Once a system gets the proper UTC time, the time zone will offset the time to the local time.

    UTC time is split into days, hours, minutes and seconds. As followed by everyone, each day is 24 hours, each hour 60 minutes, and each minute 60 seconds. Each day is made up of 86,400 seconds (defined as an SI unit).

    NOTE: Since the second is an SI unit, it can be divided using the metric system. Such as a second divided into thousands makes a millisecond. A millionth of a second is a microsecond and one billionth of a second is a nanosecond. Other metric units can be used like kilosecond, a thousand seconds, but the term is rarely used.

    The Marzullo algorithm is used to determine a close time server. The algorithm can factor in network speed issues to determine the best server.

    When using the Internet to synchronize a computer’s time with UTC, the time can be accurate to tens of milliseconds over the Internet. Accuracy over a Local Area Network (LAN) can be to a single millisecond. Be aware that routers and network congestion, which slows down frames, can cause loss of accuracy.

    NOTE: Due to the loss of accuracy over the Internet, it is best for some companies to have one system designated as a Time Server. The Time Server will synchronize its time with the Internet Time Servers. Other systems on the network will then synchronize with the company Time Server over the LAN.

    NTP uses User Datagram Protocol (UDP) on Port 123 to synchronize time.

    UTC Clocks are referenced by Stratum. Basically, each stratum is a level of accuracy where the top level, or most accurate systems, is numbered as Stratum 0 (Reference Clocks). Stratum 0 is made up of atomic clocks, GPS clocks and the like. Stratum 1 clocks receive their time from the Stratum 0 clocks. Stratum 1 clocks will have slight accuracy issues, but usually only an issue of a few microseconds since there is a direct connection to the Stratum 0 devices. Stratum 1 clocks are referred to as Primary Time Servers. Of course, the Stratum levels are now based off the layer above it and can become less accurate. In most cases though, microsecond accuracy is not required.

    NOTE: Only Stratums 0-15 are defined as valid. Any system that is Stratum 16 or lower is considered unsynchronized. Too much accuracy is lost at this point. If each exchange of time from each Stratum level to the next was a loss of 100ms accuracy, a total of 1.5 seconds can be lost over 15 Stratum.

    NTP uses 64-bit Time Stamps to exchange information. Two parts are used, 32-bits for seconds and 32-bits for portions of a second. The 64-bit Time Stamp can manage 136 years of time based from January 1, 1970. The NTP Time Stamp will start over on January 19, 2038 to use January 1, 2038 as the new starting point or a different sized Time Stamp must be adopted. Future versions of NTP may adopt a 128-bit Time Stamp. In this case, the number of seconds will be a 64-bit section and another 64-bit section for parts of a second.

    NOTE: The Time Stamp problem is sometimes referred to as the UNIX Millennium Bug.

    When a system wants to synchronize its time, it can poll three or more Time Servers. Recall that the frames are sent as UDP which are connectionless. Connectionless frames may or may not be received at the destination and no errors are generated if they are lost.

    To determine time lag, a host will send a UDP frame to a Time Server. The frame includes the Time Stamp of the request (t0). The Time Server will note the time when the packet was received (t1) and also when it was sent back to the host (t2). All of these times are included in the frame to the host. The host will then note the time when the frame is received (t3). These times can help determine the round trip delay time. This is the time it takes a request to be responded to by a Time Server, not counting the time the server took to check its time and create the frame. The equation is as follows:

    Round Trip Delay = (t3 – t0) – (t2 - t1)

    We now know the length of time the frame was en route. We also need to know the offset. The offset is found by the following:

    Offset = ((t1 - t0) + (t3 – t2)) / 2

    The offset is the actual time in transit divided by two to find how long the frame took to get to or from the Time Server.

    The Round Trip Delay and the Offset are then analyzed statistically from all servers and the clock time is adjusted as needed.

    NOTE: Simple Network Time Protocol (SNTP) is the same as NTP, but with less accuracy for devices which do not require the higher accuracy of NTP.


    Install the NTP Daemon on your Linux system. Open the NTP configuration file as follows:

    sudo nano /etc/ntp.conf

    The file should contain the following, or something similar:

    server 0.ubuntu.pool.ntp.org
    server 1.ubuntu.pool.ntp.org
    server 2.ubuntu.pool.ntp.org
    server 3.ubuntu.pool.ntp.org

    These servers can be set specifically for your country by changing the Ubuntu to your country code. Such as:
    server 0.us.pool.ntp.org
    server 1.us.pool.ntp.org
    server 2.us.pool.ntp.org
    server 3.us.pool.ntp.org

    You may also put in the address of local Time Servers and if possible Stratum 1 servers.

    Attached Files:

Share This Page