SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / server / Questions / 220836
Accepted
John Bachir
John Bachir
Asked: 2011-01-11 12:39:11 +0800 CST2011-01-11 12:39:11 +0800 CST 2011-01-11 12:39:11 +0800 CST

Why is ntpd not updating the time on my server?

  • 772

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.

ubuntu time ntp ntpd openntpd
  • 9 9 Answers
  • 140893 Views

9 Answers

  • Voted
  1. Dave Drager
    2011-01-11T12:48:51+08:002011-01-11T12:48:51+08:00

    You can enable logging in ntpd by adding this to ntp.conf:

    logfile /var/log/ntpd.log
    

    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:

    # ntpdate ntp.ubuntu.com
    10 Jan 23:47:57 ntpdate[26284]: Can't adjust the time of day: Operation not permitted
    

    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.

    • 12
  2. Best Answer
    John Bachir
    2011-01-21T12:14:42+08:002011-01-21T12:14:42+08:00

    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:

    driftfile /var/lib/ntp/ntp.drift
    
    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
    
    server ntp.ubuntu.com
    
    restrict -4 default kod notrap nomodify nopeer noquery
    restrict -6 default kod notrap nomodify nopeer noquery
    
    restrict 127.0.0.1
    restrict ::1
    

    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:

    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. This will make sure the server instance isn't following the clock on the host server.

    and:

    I think you may be mis-understanding the exact degree to which this issue affects NTP clients in a virtualized environment. In my experience on a virtualized system on a Xen host (such as our setup at Rackspace Cloud) the inaccuracy inherited by not having a dedicated system clock to process the interrupts amounts to fractions of a second, even on highly loaded systems. This slight inaccuracy is easily managed by NTP even if it is only set to update the servers time once per day (or even less frequent than that).

    • 7
  3. David Mackintosh
    2011-01-11T14:40:40+08:002011-01-11T14:40:40+08:00

    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.

    • 4
  4. Phil P
    2011-01-18T02:15:40+08:002011-01-18T02:15:40+08:00

    Things I've found in the past, when I used ntpd instead of openntpd:

    1. You need to permit access to localhost for ntpd to start properly and actually do stuff

      restrict 127.0.0.1
      restrict ::1
      
    2. 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.

    3. You don't mention using restrict to open access back up to your servers. That's an issue. Try blocks such as the following:

      # ntp.xs4all.nl
      server          194.109.22.18
      restrict        194.109.22.18
      
    4. 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.

    5. To lock down the default access, I could use:

      restrict default notrust nomodify
      

      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 of notrust. sigh

    6. If 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.

    • 4
  5. Robert
    2019-07-03T08:06:02+08:002019-07-03T08:06:02+08:00
    • If ntpd wouldn't be able to connect with the remote server, you wouldn't see an offset for that server.
    • If ntpq would be blocked by ntpd, you would see a clear error message from ntpq.
    • If some other service would set also the time (like vmware tools), you would see a jumping offset for the server (run ntpq -p every 70 seconds).

    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.

    • 4
  6. Wayne Sweatt
    2012-05-09T13:26:00+08:002012-05-09T13:26:00+08:00

    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:

    # Set to 'yes' to sync hw clock after successful ntpdate
    SYNC_HWCLOCK=no
    

    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!

    • 2
  7. Skippy le Grand Gourou
    2022-04-21T01:55:39+08:002022-04-21T01:55:39+08:00

    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]

    • 1
  8. Elgreco08
    2011-01-18T01:05:57+08:002011-01-18T01:05:57+08:00

    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

    • 0
  9. Premjith
    2011-01-18T03:16:52+08:002011-01-18T03:16:52+08:00

    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

    • 0

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    Ping a Specific Port

    • 18 Answers
  • Marko Smith

    Check if port is open or closed on a Linux server?

    • 7 Answers
  • Marko Smith

    How to automate SSH login with password?

    • 10 Answers
  • Marko Smith

    How do I tell Git for Windows where to find my private RSA key?

    • 30 Answers
  • Marko Smith

    What's the default superuser username/password for postgres after a new install?

    • 5 Answers
  • Marko Smith

    What port does SFTP use?

    • 6 Answers
  • Marko Smith

    Resolve host name from IP address

    • 8 Answers
  • Marko Smith

    Command line to list users in a Windows Active Directory group?

    • 9 Answers
  • Marko Smith

    What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?

    • 3 Answers
  • Marko Smith

    How to determine if a bash variable is empty?

    • 15 Answers
  • Martin Hope
    Davie Ping a Specific Port 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    Smudge Our security auditor is an idiot. How do I give him the information he wants? 2011-07-23 14:44:34 +0800 CST
  • Martin Hope
    kernel Can scp copy directories recursively? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh returns "Bad owner or permissions on ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil How to automate SSH login with password? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin How do I deal with a compromised server? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner How can I sort du -h output by size 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent How to determine if a bash variable is empty? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus How do you find what process is holding a file open in Windows? 2009-05-01 16:47:16 +0800 CST

Related Questions

Trending Tags

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve