From wikistone
Jump to: navigation, search
Line 97: Line 97:
  
 
Default restriction list entries, with the flags ignore, interface, ntpport, for each of the local host's interface addresses are inserted into the table at startup to prevent the server from attempting to synchronize to its own time. A default entry is also always present, though if it is otherwise unconfigured; no flags are associated with the default entry (i.e., everything besides your own NTP server is unrestricted).
 
Default restriction list entries, with the flags ignore, interface, ntpport, for each of the local host's interface addresses are inserted into the table at startup to prevent the server from attempting to synchronize to its own time. A default entry is also always present, though if it is otherwise unconfigured; no flags are associated with the default entry (i.e., everything besides your own NTP server is unrestricted).
−
* clientlimit limit : Set the client_limit variable, which limits the number of simultaneous access-controlled clients. The default value for this variable is 3.
+
* clientlimit [natural_number] : Set the client_limit variable, which limits the number of simultaneous access-controlled clients. The default value for this variable is 3.
−
* clientperiod period : Set the client_limit_period variable, which specifies the number of seconds after which a client is considered inactive and thus no longer is counted for client limit restriction. The default value for this variable is 3600 seconds.
+
* clientperiod [natural_number] : Set the client_limit_period variable, which specifies the number of seconds after which a client is considered inactive and thus no longer is counted for client limit restriction. The default value for this variable is 3600 seconds.
  
 
===Address & Mask Restrictions===
 
===Address & Mask Restrictions===

Revision as of 12:24, 18 November 2013

Status Readings

ntpq

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 LOCAL(0)        LOCAL(0)        10 l   32   64  377    0.000    0.000   0.004
*10.247.107.114  .GPS.            1 -  858 1024  377   37.950    5.226  18.515
  • Remote is the first 15 characters of the remote server's name, prefixed by a character that indicates the status of the remote server:
    • space (reject) The peer is discarded as unreachable, synchronized to this server (synch loop) or outrageous synchronization distance.
    • x (falsetick) The peer is discarded by the intersection algorithm as a falseticker.
    • . (excess) The peer is discarded as not among the first ten peers sorted by synchronization distance and so is probably a poor candidate for further consideration.
    • - (outlyer) The peer is discarded by the clustering algorithm as an outlyer.
    • + (candidate) The peer is a survivor and a candidate for the combining algorithm.
    • # (selected) The peer is a survivor, but not among the first six peers sorted by synchronization distance. If the association is ephemeral, it may be demobilized to conserve resources.
    • * (peer) The peer has been declared the system peer and lends its variables to the system variables.
    • o ((pps.peer)) The peer has been declared the system peer and lends its variables to the system variables. However, the actual system synchronization is derived from a pulse-per-second (PPS) signal, either indirectly via the PPS reference clock driver or directly via kernel interface.
  • Refid is the remote server's current source for time. If this is 0.0.0.0 or something similar, you are not getting time service from the remote server.
  • St is the remote server's current stratum level. If this is 16, you are not getting time service from the remote server.
  • t is the type of the source; (u)nicast, (m)ulticast, (l)ocal, possibly others.
  • when is the number of seconds since a time service reply has been received from the remote server.
  • poll is the number of seconds between polls of the remote server.
  • reach is an octal bitmap of the results of the last eight polls of the remote server. A value of 377 means that the last eight attempts were successful; a value of 0 means that the last eight attempts were unsuccessful (you are not getting time service from the remote server).
  • delay is the number of milliseconds it is taking for NTP packets to make the round-trip from your host to the remote server and back, and is an important factor used by NTP in selecting the "best" server. This is the reason you want to pick servers that are close to you.
  • offset is the difference in milliseconds between the clocks in your host and the remote server.
  • jitter (or disp) is the "dispersion" in milliseconds of successive time values from the remote server. It is a measure of the stability (time-wise) of the network path to the remote server, and is also an important factor used by NTP in selecting the "best" server.

Query Programs

Three utility query programs are included with the distribution, ntpq, ntptrace and ntpdc. ntpq is a handy program which sends queries and receives responses using NTP standard mode-6 control messages. Since it uses the standard control protocol specified in RFC- 1305, it may be used with NTP Version 2 and Version 3 implementations for both Unix and Fuzzball, but not Version 1 implementations. It is most useful to query remote NTP implementations to assess timekeeping accuracy and expose bugs in configuration or operation.

ntptrace can be used to display the current synchronization path from a selected host through possibly intervening servers to the primary source of synchronization, usually a radio clock. It works with both version 2 and version 3 servers, but not version 1.

ntpdc is a horrid program which uses NTP private mode-7 control messages to query local or remote servers. The format and contents of these messages are specific to this version of ntpd and some older versions. The program does allow inspection of a wide variety of internal counters and other state data, and hence does make a pretty good debugging tool, even if it is frustrating to use. The other thing of note about ntpdc is that it provides a user interface to the run time reconfiguration facility. See the respective document pages for details on the use of these programs

Status Commands

# ntpdc -c <command>
OR 
# ntpdc
ntpdc> ?
Commands available:
addpeer      addrefclock  addserver    addtrap      authinfo
broadcast    clkbug       clockstat    clrtrap      controlkey
ctlstats     debug        delay        delrestrict  disable
dmpeers      enable       exit         fudge        help
host         hostnames    iostats      kerninfo     keyid
keytype      listpeers    loopinfo     memstats     monlist
passwd       peers        preset       pstats       quit
readkeys     requestkey   reset        reslist      restrict
showpeer     sysinfo      sysstats     timeout      timerstats
traps        trustedkey   unconfig     unrestrict   untrustedkey
  • loopinfo:
    • poll adjust: how much to adjust the poll interval (+ -> less frequently, - -> more frequently) between minpoll (default 64 sec) and maxpoll (default 1024 sec)
    • watchdog: time since last poll
  • kerninfo: current remaining correction info

Watch changes manually:

# ntptrace [server]

Resync clock to NTP source:

# service ntpd stop
# ntpdate -s [server]
# service ntpd start

Or set the -x and -g options described below for the service init process and just restart the service (preferred).

Server Control Options

Access Control Support

ntpd implements a general purpose address-and-mask based restriction list. The list is sorted by address and by mask, and the list is searched in this order for matches, with the last match found defining the restriction flags associated with the incoming packets. The source address of incoming packets is used for the match, with the 32- bit address being and'ed with the mask associated with the restriction entry and then compared with the entry's address (which has also been and'ed with the mask) to look for a match. Additional information and examples can be found in the Notes on Configuring NTP and Setting up a NTP Subnet page.

The restriction facility was implemented in conformance with the access policies for the original NSFnet backbone time servers. While this facility may be otherwise useful for keeping unwanted or broken remote time servers from affecting your own, it should not be considered an alternative to the standard NTP authentication facility. Source address based restrictions are easily circumvented by a determined cracker.

The Kiss-of-Death Packet

Ordinarily, packets denied service are simply dropped with no further action except incrementing statistics counters. Sometimes a more proactive response is needed, such as a server message that explicitly requests the client to stop sending and leave a message for the system operator. A special packet format has been created for this purpose called the kiss-of-death packet. If the kod flag is set and either service is denied or the client limit is exceeded, the server it returns the packet and sets the leap bits unsynchronized, stratum zero and the ASCII string "DENY" in the reference source identifier field. If the kod flag is not set, the server simply drops the packet.

A client or peer receiving a kiss-of-death packet performs a set of sanity checks to minimize security exposure. If this is the first packet received from the server, the client assumes an access denied condition at the server. It updates the stratum and reference identifier peer variables and sets the access denied (test 4) bit in the peer flash variable. If this bit is set, the client sends no packets to the server. If this is not the first packet, the client assumes a client limit condition at the server, but does not update the peer variables. In either case, a message is sent to the system log.

Access Control Commands

  • restrict numeric_address [mask numeric_mask] [flag][...]

The numeric_address argument, expressed in dotted- quad form, is the address of an host or network. The mask argument, also expressed in dotted-quad form, defaults to 255.255.255.255, meaning that the numeric_address is treated as the address of an individual host. A default entry (address 0.0.0.0, mask 0.0.0.0) is always included and, given the sort algorithm, is always the first entry in the list. Note that, while numeric_address is normally given in dotted-quad format, the text string default, with no mask option, may be used to indicate the default entry. In the current implementation, flag always restricts access, i.e., an entry with no flags indicates that free access to the server is to be given. The flags are not orthogonal, in that more restrictive flags will often make less restrictive ones redundant. The flags can generally be classed into two catagories, those which restrict time service and those which restrict informational queries and attempts to do run-time reconfiguration of the server. One or more of the following flags may be specified:

  • kod : If access is denied, send a kiss-of-death packet.
  • ignore : Ignore all packets from hosts which match this entry. If this flag is specified neither queries nor time server polls will be responded to.
  • noquery : Ignore all NTP mode 6 and 7 packets (i.e. information queries and configuration requests) from the source. Time service is not affected.
  • nomodify : Ignore all NTP mode 6 and 7 packets which attempt to modify the state of the server (i.e. run time reconfiguration). Queries which return information are permitted.
  • notrap : Decline to provide mode 6 control message trap service to matching hosts. The trap service is a subsystem of the mode 6 control message protocol which is intended for use by remote event logging programs.
  • lowpriotrap : Declare traps set by matching hosts to be low priority. The number of traps a server can maintain is limited (the current limit is 3). Traps are usually assigned on a first come, first served basis, with later trap requestors being denied service. This flag modifies the assignment algorithm by allowing low priority traps to be overridden by later requests for normal priority traps.
  • noserve : Ignore NTP packets whose mode is other than 6 or 7. In effect, time service is denied, though queries may still be permitted.
  • nopeer : Provide stateless time service to polling hosts, but do not allocate peer memory resources to these hosts even if they otherwise might be considered useful as future synchronization partners.
  • notrust : Treat these hosts normally in other respects, but never use them as synchronization sources.
  • limited : These hosts are subject to limitation of number of clients from the same net. Net in this context refers to the IP notion of net (class A, class B, class C, etc.). Only the first client_limit hosts that have shown up at the server and that have been active during the last client_limit_period seconds are accepted. Requests from other clients from the same net are rejected. Only time request packets are taken into account. Query packets sent by the ntpq and ntpdc programs are not subject to these limits. A history of clients is kept using the monitoring capability of ntpd. Thus, monitoring is always active as long as there is a restriction entry with the limited flag.
  • ntpport : This is actually a match algorithm modifier, rather than a restriction flag. Its presence causes the restriction entry to be matched only if the source port in the packet is the standard NTP UDP port (123). Both ntpport and non-ntpport may be specified. The ntpport is considered more specific and is sorted later in the list.
  • version : Ignore these hosts if not the current NTP version.

Default restriction list entries, with the flags ignore, interface, ntpport, for each of the local host's interface addresses are inserted into the table at startup to prevent the server from attempting to synchronize to its own time. A default entry is also always present, though if it is otherwise unconfigured; no flags are associated with the default entry (i.e., everything besides your own NTP server is unrestricted).

  • clientlimit [natural_number] : Set the client_limit variable, which limits the number of simultaneous access-controlled clients. The default value for this variable is 3.
  • clientperiod [natural_number] : Set the client_limit_period variable, which specifies the number of seconds after which a client is considered inactive and thus no longer is counted for client limit restriction. The default value for this variable is 3600 seconds.

Address & Mask Restrictions

The address-and-mask configuration facility supported by ntpd is quite flexible and general, but is not an integral part of the NTP Version 3 specification. The major drawback is that, while the internal implementation is very nice, the user interface is not. For this reason it is probably worth doing an example here. Briefly, the facility works as follows. There is an internal list, each entry of which holds an address, a mask and a set of flags. On receipt of a packet, the source address of the packet is compared to each entry in the list, with a match being posted when the following is true:

(source_addr & mask) == (address & mask)

A particular source address may match several list entries. In this case the entry with the most one bits in the mask is chosen. The flags associated with this entry are used to control the access.

In the current implementation the flags always add restrictions. In effect, an entry with no flags set leaves matching hosts unrestricted. An entry can be added to the internal list using a restrict declaration. The flags associated with the entry are specified textually. For example, the notrust flag indicates that hosts matching this entry, while treated normally in other respects, shouldn't be trusted to provide synchronization even if otherwise so enabled. The nomodify flag indicates that hosts matching this entry should not be allowed to do run-time configuration. There are many more flags, see the ntpd page.

Now the example. Suppose you are running the server on a host whose address is 128.100.100.7. You would like to ensure that run time reconfiguration requests can only be made from the local host and that the server only ever synchronizes to one of a pair of off-campus servers or, failing that, a time source on net 128.100. The following entries in the configuration file would implement this policy:

     # by default, don't trust and don't allow modifications
     restrict default notrust nomodify

     # these guys are trusted for time, but no modifications allowed
     restrict 128.100.0.0 mask 255.255.0.0 nomodify
     restrict 128.8.10.1 nomodify
     restrict 192.35.82.50 nomodify

     # the local addresses are unrestricted
     restrict 128.100.100.7
     restrict 127.0.0.1

The first entry is the default entry, which all hosts match and hence which provides the default set of flags. The next three entries indicate that matching hosts will only have the nomodify flag set and hence will be trusted for time. If the mask isn't specified in the restrict keyword, it defaults to 255.255.255.255. Note that the address 128.100.100.7 matches three entries in the table, the default entry (mask 0.0.0.0), the entry for net 128.100 (mask 255.255.0.0) and the entry for the host itself (mask 255.255.255.255). As expected, the flags for the host are derived from the last entry since the mask has the most bits set.

The only other thing worth mentioning is that the restrict declarations apply to packets from all hosts, including those that are configured elsewhere in the configuration file and even including your clock pseudopeer(s), if any. Hence, if you specify a default set of restrictions which you don't wish to be applied to your configured peers, you must remove those restrictions for the configured peers with additional restrict declarations mentioning each peer separately.

Authentication

ntpd supports the optional authentication procedure specified in the NTP Version 2 and 3 specifications. Briefly, when an association runs in authenticated mode, each packet transmitted has appended to it a 32-bit key ID and a 64/128-bit cryptographic checksum of the packet contents computed using either the Data Encryption Standard (DES) or Message Digest (MD5) algorithms. Note that, while either of these algorithms provide sufficient protection from message- modification attacks, distribution of the former algorithm implementation is restricted to the U.S. and Canada, while the latter presently is free from such restrictions. For this reason, the DES algorithm is not included in the current distribution. Directions for obtaining it in other countries is in the Building and Installing the Distribution page. With either algorithm the receiving peer recomputes the checksum and compares it with the one included in the packet. For this to work, the peers must share at least one encryption key and, furthermore, must associate the shared key with the same key ID.

This facility requires some minor modifications to the basic packet processing procedures, as required by the specification. These modifications are enabled by the enable auth configuration declaration, which is currently the default. In authenticated mode, peers which send unauthenticated packets, peers which send authenticated packets which the local server is unable to decrypt and peers which send authenticated packets encrypted using a key we don't trust are all marked untrustworthy and unsuitable for synchronization. Note that, while the server may know many keys (identified by many key IDs), it is possible to declare only a subset of these as trusted. This allows the server to share keys with a client which requires authenticated time and which trusts the server, but which is not trusted by the server. Also, some additional configuration language is required to specify the key ID to be used to authenticate each configured peer association. Hence, for a server running in authenticated mode, the configuration file might look similar to the following:

     # peer configuration for 128.100.100.7
     # (expected to operate at stratum 2)
     # fully authenticated this time

     peer 128.100.49.105 key 22 # suzuki.ccie.utoronto.ca
     peer 128.8.10.1 key 4    # umd1.umd.edu
     peer 192.35.82.50 key 6  # lilben.tn.cornell.edu

     keys /usr/local/etc/ntp.keys  # path for key file
     trustedkey 1 2 14 15     # define trusted keys
     requestkey 15            # key (7) for accessing server variables
     controlkey 15            # key (6) for accessing server variables

     authdelay 0.000094       # authentication delay (Sun4c/50 IPX)

There are a couple of previously unmentioned things in here. The keys line specifies the path to the keys file (see below and the ntpd document page for details of the file format). The trustedkey declaration identifies those keys that are known to be uncompromised; the remainder presumably represent the expired or possibly compromised keys. Both sets of keys must be declared by key identifier in the ntp.keys file described below. This provides a way to retire old keys while minimizing the frequency of delicate key-distribution procedures. The requestkey line establishes the key to be used for mode-6 control messages as specified in RFC-1305 and used by the ntpq utility program, while the controlkey line establishes the key to be used for mode-7 private control messages used by the ntpdc utility program. These keys are used to prevent unauthorized modification of daemon variables.

Ordinarily, the authentication delay; that is, the processing time taken between the freezing of a transmit timestamp and the actual transmission of the packet when authentication is enabled (i.e. more or less the time it takes for the DES or MD5 routine to encrypt a single block) is computed automatically by the daemon. If necessary, the delay can be overridden by the authdelay line, which is used as a correction for the transmit timestamp. Additional utility programs included in the ./authstuff directory can be used to generate random keys, certify implementation correctness and display sample keys. As a general rule, keys should be chosen randomly, except possibly the request and control keys, which must be entered by the user as a password.

The ntp.keys file contains the list of keys and associated key IDs the server knows about (for obvious reasons this file is better left unreadable by anyone except root). The contents of this file might look like:

     # ntp keys file (ntp.keys)
     1    N   29233E0461ECD6AE    # DES key in NTP format
     2    M   RIrop8KPPvQvYotM    # md5 key as an ASCII random string
     14   M   sundial             # md5 key as an ASCII string
     15   A   sundial             # DES key as an ASCII string

     # the following 3 keys are identical
     10   A    SeCReT
     10   N    d3e54352e5548080
     10   S    a7cb86a4cba80101

In the keys file the first token on each line indicates the key ID, the second token the format of the key and the third the key itself. There are four key formats. An A indicates a DES key written as a 1- to-8 character string in 7-bit ASCII representation, with each character standing for a key octet (like a Unix password). An S indicates a DES key written as a hex number in the DES standard format, with the low order bit (LSB) of each octet being the (odd) parity bit. An N indicates a DES key again written as a hex number, but in NTP standard format with the high order bit of each octet being the (odd) parity bit (confusing enough?). An M indicates an MD5 key written as a 1-to-31 character ASCII string in the A format. Note that, because of the simple tokenizing routine, the characters ' ', '#', '\t', '\n' and '\0' can't be used in either a DES or MD5 ASCII key. Everything else is fair game, though. Key 0 (zero) is used for special purposes and should not appear in this file.

The big trouble with the authentication facility is the keys file. It is a maintenance headache and a security problem. This should be fixed some day. Presumably, this whole bag of worms goes away if/when a generic security regime for the Internet is established. An alternative with NTP Version 4 is the autokey feature, which uses random session keys and public-key cryptography and avoids the key file entirely. While this feature is not completely finished yet, details can be found in the Release Notes page.

Subnet Tuning

There are several parameters available for tuning the NTP subnet for maximum accuracy and minimum jitter. One of these is the prefer configuration declaration described in Mitigation Rules and the prefer Keyword documentation page. When more than one eligible server exists, the NTP clock-selection and combining algorithms act to winnow out all except the "best" set of servers using several criteria based on differences between the readings of different servers and between successive readings of the same server. The result is usually a set of surviving servers that are apparently statistically equivalent in accuracy, jitter and stability. The population of survivors remaining in this set depends on the individual server characteristics measured during the selection process and may vary from time to time as the result of normal statistical variations. In LANs with high speed RISC-based time servers, the population can become somewhat unstable, with individual servers popping in and out of the surviving population, generally resulting in a regime called clockhopping.

When only the smallest residual jitter can be tolerated, it may be convenient to elect one of the servers at each stratum level as the preferred one using the keyword prefer on the configuration declaration for the selected server:

     # preferred server declaration
     peer rackety.udel.edu prefer   # preferred server

The preferred server will always be included in the surviving population, regardless of its characteristics and as long as it survives preliminary sanity checks and validation procedures.

The most useful application of the prefer keyword is in high speed LANs equipped with precision radio clocks, such as a GPS receiver. In order to insure robustness, the hosts need to include outside peers as well as the GPS-equipped server; however, as long as that server is running, the synchronization preference should be that server. The keyword should normally be used in all cases in order to prefer an attached radio clock. It is probably inadvisable to use this keyword for peers outside the LAN, since it interferes with the carefully crafted judgement of the selection and combining algorithms.

# push a server to a lower stratum
fudge 169.254.0.100 stratum 10

Pushing to stratum 15 or greater means the server is unused. There are other fudges like to adjust the offset, jitter, etcetera. These are in the references.

Packet Versioning

An NTP implementation conforming to a previous version specification ordinarily discards packets from a later version. However, in most respects documented in RFC-1305, The version 2 implementation is compatible with the version 3 algorithms and protocol. The version 1 implementation contains most of the version 2 algorithms, but without important features for clock selection and robustness. Nevertheless, in most respects the NTP versions are backwards compatible. The sticky part here is that, when a previous version implementation receives a packet claiming to be from a version 4 server, it discards it without further processing. Hence there is a danger that in some situations synchronization with previous versions will fail.

The trouble occurs when an previous version is to be included in an ntpd configuration file. With no further indication, ntpd will send packets claiming to be version 4 when it polls. To get around this, ntpd allows a qualifier to be added to configuration entries to indicate which version to use when polling. Hence the entries

     # specify NTP version
     server mimsy.mil version 1     # server running ntpd version 1
     server apple.com version 2     # server running ntpd version 2

will cause version 1 packets to be sent to the host mimsy.mil and version 2 packets to be sent to apple.com. If you are testing ntpd against previous version servers you will need to be careful about this. Note that, as indicated in the RFC-1305 specification, there is no longer support for the original NTP specification, once called NTP Version 0.

Adjustments

Method

  • < 0.128 s : Normal slew is performed via adjtime().
  • < 1000.000 s : Step is performed via settimeofday().
  • > 1000.000 s : No syncing is performed.

Adjustments on Service Start

  • -x : run ntpdate on service start
  • -g : allow any size step to adjust clock on start
  • SYNC_HWCLOCK=yes : adjust hardware clock to time from ntpdate
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
SYNC_HWCLOCK=yes
NTPDATE_OPTIONS=""

Monitoring

ntpd handles peers whose stratum is higher than the stratum of the local server and polls using client mode by a fast path which minimizes the work done in responding to their polls, and normally retains no memory of these pollers. Sometimes, however, it is interesting to be able to determine who is polling the server, and how often, as well as who has been sending other types of queries to the server.

To allow this, ntpd implements a traffic monitoring facility which records the source address and a minimal amount of other information from each packet which is received by the server. This feature is normally enabled, but can be disabled if desired using the configuration file entry:

     # disable monitoring feature
     disable monitor

The recorded information can be displayed using the ntpdc query program.

Boxen Load

  • Unencrypted NTP: 90 byte packets at L2, 76 at L3/IP.
  • Encrypted NTP: <128 byte packets.

Given a single core box with 100Mb network, load is 2-3% for Encrypted given about 4k requests per second.

References

Clock Select Algorithm: DTSS

NTP Clock Select Algorithm

Web Links

Server Control Options: http://doc.ntp.org/4.1.2/accopt.htm

NTP FAQ on the algorithm: http://www.ntp.org/ntpfaq/NTP-s-algo.htm

NTP explanation: http://networking.ringofsaturn.com/Protocols/ntp.php

Detailed explanation: http://www.eecis.udel.edu/~mills/ntp/html/notes.html

.