Difference between revisions of "NTPD"

From IPLOG
Jump to: navigation, search
Line 88: Line 88:
 
  driftfile /tmp/ntp.drift
 
  driftfile /tmp/ntp.drift
 
  #end-of-file
 
  #end-of-file
 +
 +
 +
 +
== Diagnostics ==
 +
=== NTPQ ===
 +
The '''ntpq''' utility program is used to query NTP servers which implement the recommended NTP mode 6 control message format about current state and to request changes in that state.
 +
 +
[http://doc.ntp.org/4.2.8p9/ntpq.html NTPQ Home Page]
 +
 +
 +
Example:
 +
{{NotePre|text= root@iplog:~# watch ntpq -p -n
 +
}}
 +
NTPQ Parameters:
 +
 +
: '''watch''' - Every 2s: ntpq -p -n
 +
 +
: '''-p''' - Print current status
 +
 +
: '''-n''' - Disable DNS resolving
 +
 +
Every 2s: ntpq -p -n                                        2019-08-01 10:00:12
 +
 +
      remote          refid      st t when poll reach  delay  offset  jitter
 +
==============================================================================
 +
  127.127.1.0    .ILOG.          10 l  41m  64    0    0.000    0.000  0.000
 +
+195.113.144.201 195.113.144.238  2 u  92  128  377  12.307    2.212  1.333
 +
*195.113.144.238 .GPS.            1 u  20  128  377  11.039    4.785  1.630
 +
 +
 +
This section is a copy from https://pthree.org/2013/11/05/real-life-ntp/.
 +
 +
Parameters:
 +
 +
:    • '''remote''' – The remote server you wish to synchronize your clock with
 +
 +
:        ◦ " " Discarded as not valid. Could be that you cannot communicate with the remote machine (it's not online), this time source is a ".LOCL." refid time source, it's a high stratum server, or the remote server is using this computer as an NTP server.
 +
 +
:        ◦ "x" Discarded by the intersection algorithm.
 +
 +
:        ◦ "." Discarded by table overflow (not used).
 +
 +
:        ◦ "-" Discarded by the cluster algorithm.
 +
 +
:        ◦ "+" Included in the combine algorithm. This is a good candidate if the current server we are synchronizing with is discarded for any reason.
 +
 +
:        ◦ "#" Good remote server to be used as an alternative backup. This is only shown if you have more than 10 remote servers.
 +
 +
:        ◦ "*" The current system peer. The computer is using this remote server as its time source to synchronize the clock
 +
 +
:        ◦ "o" Pulse per second (PPS) peer. This is generally used with GPS time sources, although any time source delivering a PPS will do. This tally code and the previous tally code "*" will not be displayed simultaneously.
 +
 +
:    • '''refid''' – The upstream stratum to the remote server. For stratum 1 servers, this will be the stratum 0 source.
 +
 +
:    • '''st''' – The stratum level, 0 through 16.
 +
 +
:    • '''t''' –  The type of connection.
 +
 +
:        ◦ l = local reference clock
 +
 +
:        ◦ u = unicast (most common)
 +
 +
:        ◦ m = multicast
 +
 +
:        ◦ b = broadcast
 +
 +
:    • '''when''' – The last time when the server was queried for the time. Default is seconds, or "m" will be displayed for minutes, "h" for hours and "d" for days.
 +
 +
:    • '''poll''' – How often the server is queried for the time, with a minimum of 8 seconds to a maximum of 36 hours. It's also displayed as a value from a power of two. Typically, it's between 64 seconds and 1024 seconds.
 +
 +
:    • '''reach''' – This is an 8-bit left shift octal value that shows the success and failure rate of communicating with the remote server. Success means the bit is set, failure means the bit is not set. 377 is the highest value.
 +
 +
:    • '''delay''' – This value is displayed in milliseconds, and shows the round trip time (RTT) of your computer communicating with the remote server.
 +
 +
:    • '''offset''' –  This value is displayed in milliseconds, using root mean squares, and shows how far off your clock is from the reported time the server gave you. It can be positive or negative.
 +
 +
:    • '''jitter''' – This number is an absolute value in milliseconds, showing the root mean squared deviation of your offsets.

Revision as of 12:21, 1 August 2019

This page is being temporarily revised with the newest updates.

NTPD (Network Time Protokol Daemon)

Description

The NTPD program is an operating-system daemon that sets and maintains a computer system's system time in synchronization with Internet-standard time servers. It is a complete implementation of the Network Time Protocol (NTP) version 4, but retains compatibility with versions 1, 2, and 3 as defined by RFC 1059, RFC 1119, and RFC 1305, respectively. ntpd performs most computations in 64-bit floating point arithmetic and uses 64-bit fixed point operations only when necessary to preserve the ultimate precision, about 232 picoseconds. While ordinary workstations and networks cannot achieve the ultimate precision as of 2015, future processors and networks may require it.

NTPD Installation

To install NTPD package simply use the following commands:


1. Update List of Available Packages

root@iplog:~# opkg update

Example of update process:

Downloading http://www.iplog.eu/opkg/base/Packages.gz.
Updated source 'base'.
Downloading http://www.iplog.eu/opkg/firmware/Packages.gz.
Updated source 'firmware'.


2. Upgrade Installed Packages

root@iplog:~# opkg upgrade


3. Install NTPD Package

root@iplog:~# opkg install ntpd

Example of package installing:

Installing ntpd (4.2.8p9-9671.212083251) on root.
Downloading http://www.iplog.eu/opkg/base/ntpd_4.2.8p9-9671.212083251_all.ipk.
Configuring ntpd.


Configuration Examples

This section provides several examples of the /etc/ntpd.conf configuration file.

1. Standalone NTP server

The following configuration has the following features:

- Local NTP server with specified stratum 10
- No synchronization to internet NTP servers


Editing configuration file command:

root@iplog:~# vi /etc/ntpd.conf

File content:

restrict default
#restrict source
#interface listen wildcar
 
# create a local NTP server
server 127.127.1.0
fudge 127.127.1.0 stratum 10

driftfile /tmp/ntp.drift


2. With Connetion to Remote NTP Servers

Example shows the optimal configuration for the Czech Republic.

This configuration has the following features:

- Local NTP server with specified stratum 10
- Synchronization to two internet NTP servers


Editing configuration file command:

root@iplog:~# vi /etc/ntpd.conf

File content:

restrict default
#restrict source
#interface listen wildcard

server tik.cesnet.cz
server tak.cesnet.cz

server 127.127.1.0
fudge 127.127.1.0 stratum 10 refid ILOG

driftfile /tmp/ntp.drift
#end-of-file


Diagnostics

NTPQ

The ntpq utility program is used to query NTP servers which implement the recommended NTP mode 6 control message format about current state and to request changes in that state.

NTPQ Home Page


Example:

root@iplog:~# watch ntpq -p -n

NTPQ Parameters:

watch - Every 2s: ntpq -p -n
-p - Print current status
-n - Disable DNS resolving
Every 2s: ntpq -p -n                                        2019-08-01 10:00:12

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.1.0     .ILOG.          10 l  41m   64    0    0.000    0.000   0.000
+195.113.144.201 195.113.144.238  2 u   92  128  377   12.307    2.212   1.333
*195.113.144.238 .GPS.            1 u   20  128  377   11.039    4.785   1.630


This section is a copy from https://pthree.org/2013/11/05/real-life-ntp/.

Parameters:

remote – The remote server you wish to synchronize your clock with
◦ " " Discarded as not valid. Could be that you cannot communicate with the remote machine (it's not online), this time source is a ".LOCL." refid time source, it's a high stratum server, or the remote server is using this computer as an NTP server.
◦ "x" Discarded by the intersection algorithm.
◦ "." Discarded by table overflow (not used).
◦ "-" Discarded by the cluster algorithm.
◦ "+" Included in the combine algorithm. This is a good candidate if the current server we are synchronizing with is discarded for any reason.
◦ "#" Good remote server to be used as an alternative backup. This is only shown if you have more than 10 remote servers.
◦ "*" The current system peer. The computer is using this remote server as its time source to synchronize the clock
◦ "o" Pulse per second (PPS) peer. This is generally used with GPS time sources, although any time source delivering a PPS will do. This tally code and the previous tally code "*" will not be displayed simultaneously.
refid – The upstream stratum to the remote server. For stratum 1 servers, this will be the stratum 0 source.
st – The stratum level, 0 through 16.
t – The type of connection.
◦ l = local reference clock
◦ u = unicast (most common)
◦ m = multicast
◦ b = broadcast
when – The last time when the server was queried for the time. Default is seconds, or "m" will be displayed for minutes, "h" for hours and "d" for days.
poll – How often the server is queried for the time, with a minimum of 8 seconds to a maximum of 36 hours. It's also displayed as a value from a power of two. Typically, it's between 64 seconds and 1024 seconds.
reach – This is an 8-bit left shift octal value that shows the success and failure rate of communicating with the remote server. Success means the bit is set, failure means the bit is not set. 377 is the highest value.
delay – This value is displayed in milliseconds, and shows the round trip time (RTT) of your computer communicating with the remote server.
offset – This value is displayed in milliseconds, using root mean squares, and shows how far off your clock is from the reported time the server gave you. It can be positive or negative.
jitter – This number is an absolute value in milliseconds, showing the root mean squared deviation of your offsets.