NTP not syncing in a VM

9,777

In general NTP is good at keeping the time in sync but if the time is radically different between 2 systems then it will take NTP a while to get the times between the 2 systems in sync. I usually use ntpdate to get the time in sync first like so:

$ ntpdate -u 0.us.pool.ntp.org

And then start the NTP service afterwards. This adjusts the time in a gross way and then enlists NTP to keep the time in sync afterwards going forward.

Share:
9,777

Related videos on Youtube

Cera
Author by

Cera

Updated on September 18, 2022

Comments

  • Cera
    Cera over 1 year

    I'm managing some VirtualBox developer environments. The time drifts out of sync when the box is suspended, so I want to use NTP to keep it in sync.

    NTP doesn't seem to be doing its job, though - the time does not get updated.

    It does work if I do this:

    $ service ntp stop
    $ ntpdate au.pool.ntp.org
    $ service ntp stop
    

    Here is my /etc/ntp.conf:

    driftfile /var/lib/ntp/ntp.drift
    
    # Set tinker panic - see http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006427
    # Makes time sync more aggressively in a VM.
    tinker panic 0
    
    # Local users may interrogate the ntp server more closely.
    restrict 127.0.0.1
    restrict ::1
    
    # Specify one or more NTP servers.
    server au.pool.ntp.org
    
    # Specify one or more NTP servers.
    server 0.pool.ntp.org
    

    Here's the relevant lines from /var/log/syslog:

    Jun 20 18:51:30 vg ntpd[7239]: ntpd [email protected] Tue Jun  5 20:12:08 UTC 2012 (1)
    Jun 20 18:51:30 vg ntpd[7240]: proto: precision = 0.191 usec
    Jun 20 18:51:30 vg ntpd[7240]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
    Jun 20 18:51:30 vg ntpd[7240]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen and drop on 1 v6wildcard :: UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 2 lo 127.0.0.1 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 3 eth0 10.0.2.15 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 4 eth1 192.168.33.10 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 5 eth2 192.168.0.156 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 6 eth0 fe80::a00:27ff:fea0:5444 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 7 eth2 fe80::a00:27ff:fe1c:18ae UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 8 eth1 fe80::a00:27ff:fe02:b8f6 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: Listen normally on 9 lo ::1 UDP 123
    Jun 20 18:51:30 vg ntpd[7240]: peers refreshed
    Jun 20 18:51:30 vg ntpd[7240]: Listening on routing socket on fd #26 for interface updates
    

    In the above logs, the date is a full 14 hours behind.

    The three interfaces are a quirk of our dev environment. eth2 is the interface with an IP on the office NAT, providing internet access.

    I have NTP 4.2.6, running on Ubuntu 12.04 (Precise).

    Why is NTP not updating the time on this machine?

    • Hauke Laging
      Hauke Laging almost 11 years
      Have you tried ntpdate -b?
    • Raza
      Raza almost 11 years
      can you try add ntp server address to /etc/ntp/step-tickers and then restart the ntp service. I had a simlar issue with vmware host and it works for me.
  • Cera
    Cera almost 11 years
    This is what ticker panic 0 is meant to do, though: "The configuration directive tinker panic 0 instructs NTP not to give up if it sees a large jump in time. This is important for coping with large time drifts and also resuming virtual machines from their suspended state."
  • slm
    slm almost 11 years
    @Cerales - thanks for pointing that out, I'd never noticed the tinker option before. I found this thread over on SO that discusses your problem, specifically this answer. Try moving the tinker option to the top of the file and also make sure that you're following the recommendations in that SO Q&A too. The man page for ntp.conf also says the same thing about tinker options being the first thing in the file.