Cain Manor

Your Guide To All Things Cain™

NTP Client Setup

This doc­u­ment serves two pur­poses. The first is to doc­u­ment the setup of an NTP client (not an NTP server.) The sec­ond is to allow other to see how to mon­i­tor NTP.

Enable sync­ing with upstream servers from your NTP source. These set­tings are set in /etc/ntp.conf

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# Limiting to three servers as requested by pool.ntp.org
server myTIME01.domain.com
server myTIME02.domain.com

Now we need to make sure our time is some­what accu­rate — within a minute or so. But before we do that we have to stop the ntpd daemon.

service ntpd stop

Now sync time

ntpdate -u qantp01.qa.testlab.com

Make sure the NTP dae­mon is enabled

chkconfig --list ntpd
ntpd           	0:off	1:off	2:off	3:off	4:off	5:off	6:off

If it’s not, enable it

chkconfig --level 2345 ntpd on

and ver­ify

chkconfig --list ntpd
ntpd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off

And restart the daemon

service ntpd start

Now we need to make sure time is sync­ing cor­rectly. We can do this with ntpq \-p (or use \-np for ip’s, and not names.) This pro­vided you with a list of time servers and the delay, off­set and jit­ter that your server is expe­ri­enc­ing with them. The delay and off­set val­ues should be non-zero and the jit­ter value should be under 100. The times are in mil­lisec­onds (1/1000 of a sec­ond.) The impor­tant thing to look for is the * you see in the first line. The * means you are sync­ing with a server on the inter­net. If you don’t see it right away, wait a few min­utes and try again. It may take up to 15 minute for the local clock to get in sync with the remote server. Patience is your friend.

ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*qantp01.qa.test 209.20.66.253    3 u  113  256  377    0.165   -2.251   2.791
 LOCAL(0)        .LOCL.          10 l   27   64  377    0.000    0.000   0.001

The first char­ac­ter in the left­most col­umn indi­cates the sta­tus of the peer, fol­lowed by the name or IP of the peer

*” selected for syn­chro­niza­tion
“o” selected for syn­chro­niza­tion, PPS sig­nal in use.
”+” included in the final selec­tion set;
“sp” dis­carded as unreach­able, syn­chro­nized to this server (synch loop) or out­ra­geous syn­chro­niza­tion dis­tance;
“x” des­ig­nated fal­sticker by the inter­sec­tion algo­rithm;
”.” culled from the end of the can­di­date list;
”-” dis­carded by the clus­ter­ing algo­rithm;
”#” selected for syn­chro­niza­tion but dis­tance exceeds maximum;The third col­umn (st) is the stra­tum of your peer. LOCAL is a loop­back address used for when no other clocks are avail­able, and has a default set­ting of 10. Valid val­ues are between 1 and 15. A value of 16 is a invalid stra­tum value rep­re­sent­ing “this server is not con­sid­ered as a time provider”. This can be for var­i­ous rea­sons, the most com­mon rea­sons are “time provider not syn­chro­nized”, “con­fig­ured source does not exist” or “ntp server not running”.

The fourth col­umn indi­cates the type of server it is, and isn’t of much concern.

l = local (such as a GPS, WWVB)
u = uni­cast (most com­mon)
m = mul­ti­cast
b = broad­cast
– = netaddr

The sev­enth col­umn indi­cates reach, and should be at 377. An expla­na­tion of why from Linux Jour­nal

Each remote server or peer is assigned its own buffer by ntpd. This buffer rep­re­sents the sta­tus of the last eight NTP trans­ac­tions between the NTP dae­mon and a given remote time server. Each bit is a boolean value, where a 1 indi­cates a suc­cess­ful trans­ac­tion and a 0 indi­cates a fail­ure. Each time a new packet is sent, the entire eight-bit reg­is­ter is shifted one bit left as the newest bit enters from the right.
The net result is that dropped pack­ets can be tracked over eight poll inter­vals before falling off the end of the reg­is­ter to make room for new data. This recy­cling of space in the reg­is­ter is why it’s called a cir­cu­lar buffer, but it may make more sense to think of it in lin­ear terms, as a steady, left­ward march–eight small steps, and then the bit ends up wher­ever bits go when they die.
For rea­sons that seemed good to the devel­op­ers, this reg­is­ter is dis­played to the user in octal val­ues instead of binary, dec­i­mal or even hex. The max­i­mum value of an eight-bit binary num­ber is 11111111, which is 377 in octal, 255 in dec­i­mal and 0xFF in hex.

The ninth col­umn indi­cates off­set in mil­lisec­onds, and should be less than 150
If you want to see how accu­rate your time is, you can use

ntpdc -c loopinfo
offset:               -0.064429 s
frequency:            -19.206 ppm
poll adjust:          30
watchdog timer:       175 s

To see the remain­ing correction

[root@QANTP01 ~]# ntpdc -c kerninfo
pll offset:           4294.91 s
pll frequency:        -19.206 ppm
maximum error:        0.437245 s
estimated error:      0.06018 s
status:               0001  pll
pll time constant:    6
precision:            1e-06 s
frequency tolerance:  512 ppm

You can get the same rough infor­ma­tion from ntptime

ntptime
ntp_gettime() returns code 0 (OK)
  time cd6e9ff0.43c3e000  Fri, Mar 20 2009 16:06:24.264, (.264708),
  maximum error 468477 us, estimated error 60180 us
ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset -60495.000 us, frequency -19.206 ppm, interval 1 s,
  maximum error 468477 us, estimated error 60180 us,
  status 0x1 (PLL),
  time constant 6, precision 1.000 us, tolerance 512 ppm,

To query your time server, but not change it, you can use ntp­date –q. How­ever, you’ll need to sup­ply an IP address. I sug­gest you use the one with the * when you do an ntpq –np, as that is the one you are using for syncing.

ntpdate -q 192.168.106.34
server 192.168.106.34, stratum 3, offset -0.001684, delay 0.02576
26 Mar 16:21:46 ntpdate[23454]: adjust time server 192.168.106.34 offset -0.001684 sec

You can also use ntp­date –d to look at the same infor­ma­tion, but with debug­ging information.

ntpdate -q 192.168.106.34
server 192.168.106.34, stratum 3, offset -0.001684, delay 0.02576
26 Mar 16:21:46 ntpdate[23454]: adjust time server 192.168.106.34 offset -0.001684 sec
ntpdate -d 192.168.10.10
26 Mar 16:22:28 ntpdate[23457]: ntpdate 4.2.2p1@1.1570-o Tue Jun 10 00:07:14 UTC 2008 (1)
Looking for host 192.168.106.34 and service ntp
host found : qantp01.qa.testlab.com
transmit(192.168.106.34)
receive(192.168.106.34)
transmit(192.168.106.34)
receive(192.168.106.34)
transmit(192.168.106.34)
receive(192.168.106.34)
transmit(192.168.106.34)
receive(192.168.106.34)
transmit(192.168.106.34)
server 192.168.106.34, port 123
stratum 3, precision -20, leap 00, trust 000
refid [192.168.106.34], delay 0.02576, dispersion 0.00000
transmitted 4, in filter 4
reference time:    cd7688e3.2844bded  Thu, Mar 26 2009 16:06:11.157
originate timestamp: cd768cb4.2295b2a8  Thu, Mar 26 2009 16:22:28.135
transmit timestamp:  cd768cb4.22fc6972  Thu, Mar 26 2009 16:22:28.136
filter delay:  0.02579  0.02576  0.02579  0.02576
         0.00000  0.00000  0.00000  0.00000
filter offset: -0.00164 -0.00164 -0.00165 -0.00164
         0.000000 0.000000 0.000000 0.000000
delay 0.02576, dispersion 0.00000
offset -0.001646
 
26 Mar 16:22:28 ntpdate[23457]: adjust time server 192.168.106.34 offset -0.001646 sec

You can also use ntp­trace to watch the sys­tem time syn­chro­niza­tion (the –n flag turns off name lookups.) This will allow you to fol­low the time syn­chro­niza­tion to it’s mas­ter time source.

ntptrace -n 192.168.106.34
192.168.106.34: stratum 3, offset -0.005207, synch distance 0.299721
209.20.66.253: stratum 2, offset 0.004282, synch distance 0.061297
192.5.41.40: stratum 1, offset -0.000018, synch distance 0.000000, refid 'USNO'

If you find you are expe­ri­enc­ing trou­ble (and you’ve waited more than 15 min­utes for your client clock to sync) you can enable more exten­sive log­ging. This is part of the /etc/ntp.conf con­fig­u­ra­tion file.

# These should enable statistics to be kept
statsdir /var/log/ntp/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

Don’t for­get to make the direc­tory and make it read­able by the ntp user (which the ntp dae­mon runs as.)

mkdir /var/log/ntp/
chown ntp:ntp /var/log/ntp

Now restart ntpd

service ntpd restart

Comments are closed.