Unable to sync with ntp servers

15,996

Took me a year, but I now finally understood the issue. The server I was working on is situated in an internal network that restrict to only certain NTP servers.

Here's a list of useful steps to troubleshoot for Ubuntu 14.04 headless server

How to fix system clock drift

How to check current datetime

timedatectl status

you should see

# timedatectl status
      Local time: Mon 2018-09-17 10:49:04 +08
  Universal time: Mon 2018-09-17 02:49:04 UTC
        Timezone: Asia/Singapore (+08, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

How to see whether can access NTP servers

ntpq -p

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ns1.ericsson.se 194.58.202.148   2 u    3   64    1  237.716  1217396   0.000
 sesblx50.mgmt.e 194.58.202.148   2 u    2   64    1  242.759  1217391   0.000
 chilipepper.can .INIT.          16 u    -   64    0    0.000    0.000   0.000

If you see all showing .INIT. in refid means NOT connected to NTP server. Ask your network admin for NTP servers. This was my issue initially. If you see refid correctly pointing to some IP address, your NTP service is correctly connecting to the NTP servers.

How to update NTP servers

As root, go to vim /etc/ntp.conf

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#server 0.ubuntu.pool.ntp.org
#server 1.ubuntu.pool.ntp.org
#server 2.ubuntu.pool.ntp.org
#server 3.ubuntu.pool.ntp.org

server time1.suppliedbyadmin.com
server time2.suppliedbyadmin.com

Change this then service ntp restart

How to force ntp system time update

Even if you update to the correct ntp server, the system clock might still be wrong. So you need to force the NTP update.

  1. Stop the ntp service

  2. Force the update with ntpd -gq

  3. Then start the ntp service again

It should look like this:

 # service ntp stop
 # ntpd -gq
 ntpd: time set +1217.437601s
 # service ntp start

This should work

How to check if ntp service is running

Use service ntp status

 # service ntp status
 * NTP server is running

Even if you get that the service is running, that does not mean that the NTP service is correctly connecting to the NTP servers. Check ntpq -p command to be sure

Share:
15,996
Kim Stacks
Author by

Kim Stacks

Updated on September 18, 2022

Comments

  • Kim Stacks
    Kim Stacks over 1 year

    Server is 14.04

    My timedatectl status

    www-data@Mercury:$ timedatectl status
          Local time: Fri 2017-08-04 14:34:31 SGT
      Universal time: Fri 2017-08-04 06:34:31 UTC
            Timezone: Asia/Singapore (SGT, +0800)
         NTP enabled: no
    NTP synchronized: yes
     RTC in local TZ: no
          DST active: n/a
    

    When I run ntpq I get connection refused. I have googled around but none of the solution works for me.

    www-data@Mercury:$ sudo ntpq -p
    ntpq: read: Connection refused
    

    This is my /etc/ntp.conf

    server 0.ubuntu.pool.ntp.org
    server 1.ubuntu.pool.ntp.org
    server 2.ubuntu.pool.ntp.org
    server 3.ubuntu.pool.ntp.org
    
    # Use Ubuntu's ntp server as a fallback.
    server ntp.ubuntu.com