1

I'm trying to config ntpserver and client.what should I do to ntpd sync time more frequently and asap? when I change the time in client manually and then restart ntpd service , after 16 s time is synced.but when I change time again without restarting ntpd service or reboot server , it takes 15 to 16 min to sync the time.I want ntpd check time every 16 or 20 sec.

ntp server : 192.168.135.130 ntp client : 192.168.135.131

##server config###

driftfile` /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict time.google.com mask 255.255.255.245 nomodify notrap noquery
server time.google.com
restrict 192.168.135.0 mask 255.255.255.0
############################################################

 ##client config##

driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
server 192.168.135.130 iburst burst minpoll 4 maxpoll 4
logfile /var/log/ntp.log
logconfig all
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
###########################################################
##drift file##
-12.298
Ali
  • 25

2 Answers2

4

I think you're operating under a fundamental misconception.

ntpd is intended to run all the time, and keep the time within microseconds of a reference clock as long as it is running. It does not poll the time server every 15-20 minutes and correct the time; it is running all the time.

What I suspect you are seeing is correct behavior of the ntpd. When the daemon starts, it steps (changes drastically) the clock to correct it to the source clock, probably because it is configured to permit that behavior as a one-time change, but only on startup (otherwise it might take a very long time to converge to the right time, say if the clock read January 1st. 1970 when the computer booted).

After it starts, most of the time the ntpd is configured to NEVER step (dramatically change) the clock. Instead, it slews (gradually changes) the clock until it is correct / synchronized, so that applications that run on your computer are not negatively affected (e.g. cron scripts fail to run because you simply skipped 1AM today). I think this is what you saw when you set the time manually while ntpd was running.

If you run ntpd this way, you shouldn't ever have an incorrect (off by more than microseconds) clock on the computer, and you should never have to set / change the time yourself; this is how ntpd is intended to function.

You may be more used to another environment where you expect to synchronize the clock periodically over the network, essentially by asking another computer: "What time is it now?" and setting the clock to the answer. This has two challenges, one of which is the one you noticed (the clock may take some time to be corrected if it diverges), and the other of which is that your clock will be more inaccurate than if you used ntpd (you will be off by the latency between your computer and the time server, likely miliseconds)

I hope this information is useful to you.

0

You may be conflating 2 things - an NTP client and server.

An NTP client syncs from the server periodically, and you can set syns to be even more frequent using cron (using ntpdate for example). It sounds like this is what you want to do.

An NTP server - which is what you describe above is a lot more complex to run, and slow to start up. This is because it connects to multiple other servers and tries very hard to be very accurate, even taking latency and latency variation into account. It thus takes a long time to start.

Grnerally smaller orgs would use an Internet accessible NTP server, but larger ones - or orgs which need greater accuracy will run 1 ntp server and point clients to that +to reduce inaccuracy caused by variations in latency and reduce strain on the other servers).

EDIT

You could probably run a trivial scriptlike the one that follows in the background to keep syncing the clock (but I don't like this solution)

#! /bin/bash

NTPSERVER=clock.isc.org
SECS=20

while [ 1 ]
do
     /usr/sbin/ntpdate $NTPSERVER
     sleep $SECS
done

Let say you save this file in /usr/local/bin/keeptime -

chmod 755 /usr/local/bin/keeptime 

Will make it executable and adding

/usr/local/bin/keeptime &

near the top of /etc/rc.local will (depending on your distro), run this in the background.

davidgo
  • 73,366