I have ntpd running on my server. It's all the default settings, except I commented out its ability to be a server to other machines:
# restrict -4 default kod notrap nomodify nopeer noquery
# restrict -6 default kod notrap nomodify nopeer noquery
restrict default ignore
If I run ntpdate -q ntp.ubuntu.com
, I'm told that my machine's clock is off by 7 seconds.
What's going on? How can I diagnose what's happening, is there a log I can turn on?
more info #1
# ntpq -np
remote refid st t when poll reach delay offset jitter
==============================================================================
91.189.94.4 193.79.237.14 2 u 30 64 7 108.518 -0.136 0.361
more info #2
Here's what this looked like when I asked the question:
# ntpdate -q ntp.ubuntu.com
server 91.189.94.4, stratum 2, offset 7.191308, delay 0.13310
10 Jan 20:38:09 ntpdate[31055]: step time server 91.189.94.4 offset 7.191308 sec
And here's what it looks like now, after restarting ntpd a couple times (I'm assuming that's what fixed it):
# ntpdate -q ntp.ubuntu.com
server 91.189.94.4, stratum 2, offset 0.000112, delay 0.13164
10 Jan 20:47:03 ntpdate[31419]: adjust time server 91.189.94.4 offset 0.000112 sec
more info #3
I uninstalled ntp and installed openntpd and ran /usr/sbin/ntpd -d
, and I'm seeing output like this:
reply from 64.73.32.134: offset 6.715003 delay 0.041152, next query 30s
reply from 208.53.158.34: offset 6.700224 delay 0.036263, next query 31s
adjusting local clock by 6.734120s
reply from 72.18.205.156: offset 6.708575 delay 0.035885, next query 30s
reply from 64.73.32.134: offset 6.701463 delay 0.044199, next query 33s
Which to me pretty clearly indicates that I'm not able to set the time on my server (although, with regular ntp, it does seem to update sometimes...).
more info #4
My VPS provider says:
The latest kernels should not lock your system to our dom0's clock, to be on the safe side you can set xen.independent_wallclock = 1 in your sysctl.conf.
Which I suppose still does not address the issue of the VPS needing a CPU available in order to do correct timing calculations.
You can enable logging in ntpd by adding this to ntp.conf:
Source: ntp manual
If you turn off ntpd, can you update the clock by command line? If you run the ntpdate command and receive an error like so:
This means that you are probably on a VPS, and in that case you can not modify the system clock - this can only be done on the host machine.
Alright folks, in the time since asking this question, I've reinstalled ntp with the default vendor (Ubuntu 10.0.4) config and let it run for a few days. As of this writing,
ntpdate -q ntp.ubuntu.com
shows that my time is accurate to within 0.000216 seconds. So, the problems I was having must have been with my customized config (where I was trying to make it impossible for external hosts to query my server, which I'm already doing with my firewall so I'm not too worried about). Here is the Ubuntu 10.0.4 ntp.conf in its entirety, with comments removed:I welcome feedback on how this config might be improved.
I also made a ticket with my VPS provider asking them for a detailed recommendation on the best thing to do. I pointed them to this thread, and some other documentation indicating that maybe the CPU allocation would cause a timing problem. Here is what they said:
and:
One of your comments says you are running on a vhost. In this case, you are probably not going to have much success because your vhost's sense of time is going to be dependent both on the real host it is running on and by how busy overall the vhost is.
Depending on the virtualization used, the vhost may not get a steady share of interrupts in a given time period. This will make the clock run faster, or slower, than is really happening. Since ntp is trying to measure changes on the assumption that your clock is a fixed-rate faster or slower than the rest of the world, this speeding up and slowing down will give ntp fits and it will probably eventually just give up, with the result that
ntp -np
shows time servers that ntp has deemed unsuitable.Your best bet if this is the case is probably a brute-force
rdate -s $server
every so often (like every six hours) to yank the clock around by its nose so that it doesn't drift excessively out of sync. But fine-grained accuracy is probably out of reach.Things I've found in the past, when I used ntpd instead of openntpd:
You need to permit access to localhost for ntpd to start properly and actually do stuff
Although you can use hostnames for server rules, opening back up holes to talk with those servers means using
restrict
which requires IP addresses, so I ended up having to use IPs for everything anyway.You don't mention using
restrict
to open access back up to your servers. That's an issue. Try blocks such as the following:You need multiple peers or servers for ntpd, since it tries to use majority-rules voting to deal with a bad actor. So a minimum of 4, to still be able to have a majority when you lose one, preferably 5.
To lock down the default access, I could use:
so as to still be able to query, but I ended up using
restrict default ignore
as you do when ntpd 4.2 changed the meaning ofnotrust
. sighIf you're not providing time-service to others, then you probably don't need the full power of regular ntpd and you should consider
openntpd
instead. Written by the OpenBSD crew, it's a far more minimal implementation, using privilege separation and a much simpler config file. It allegedly won't provide the highly precise time that ntpd will, but it's easily good enough for a regular server or workstation.The
reach 7
in ntpq output indicated, that you let ntpd only run for around 4 minutes. 7 is 111 binary, which means the server was reached already 3 times. ntp reaches out every 64 seconds (poll
value) and waited already 30 seconds (when
value) since the last contact.The
offset -0.136
indicated, that the system is already synchronized. Only ntpd hasn't marked the server as source, yet. Just give it more time and a little star will appear.So, actually your ntpd was syncing. But ntpd doesn't usually sync in one big jump (like ntpdate), but tries to adjust the time slowly and ensures over several cycles, that the time is stable.
PS: I am aware, that the question is very old. But the issue is timeless. And all the other answers are just misleading IMHO. ntpd is even recommended by VMWare to keep the time in sync.
I found my system off and puzzled why the HW clock wasn't sync'ing with the system clock on a clean shutdown. Seems there's an NTP setting in sysconfig that needs editing to make that happen.
In
/etc/sysconfig/ntpd
:I set that to
yes
. Of course first verify that you have a solid NTP server and your system clock is reliable.I knew that was it - my skew was 47 seconds and my HW clock was also 47 seconds off. Bingo! My first clue was Kerberos failures seen in the logs. Kerberos and many NAS will just not work if clock skew is too great.
Have a Nice Day!
This was not OP’s issue, but another reason for ntpd not syncing could be that the ntp port (123) is blocked (e.g. by the company’s firewall).
A solution is to use htpdate, which has a daemon mode (
-D
).[credits]
if you are running vhost on vmware check the following article..it shuld help you http://www.vmware.com/files/pdf/Timekeeping-In-VirtualMachines.pdf
Hai..
Take a look at this reference to see if it can assist in troubleshooting your issue:
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:Ch24:_The_NTP_Server
you might want to post the contents of your ntpd.conf file, the output of the debug commands like ntpq -p
And check your date/time?
And verify this also, run ntpdate and startup ntpd, is the time keeping in sync?
with best wishes