How to verify NTP is working Or not (Check Status of NTP)

I have setup an NTP (Network Time Protocol) client and/or server to manage the system clock over a network. But, how do I verify that it is working correctly? How do I check the status of NTP?

Keeping the correct time is essential on a server and client system. You can use any one of the following programs to verify that NTP client configuration is working correctly on Linux or Unix-like systems.

ADVERTISEMENTS

How to check NTP is working?

  1. ntpq – standard NTP query program
  2. ntpstat – show network time synchronisation status
  3. timedatectl – show or set info about ntp using systemd
Tutorial details
Difficulty Easy (rss)
Root privileges No
Requirements None
Time 2m
Let us see all commands and examples in details

Verify NTP is working or not with ntpstat command

The ntpstat command will report the synchronisation state of the NTP daemon running on the local machine. If the local system is found to be synchronised to a reference time source, ntpstat will report the approximate time accuracy.

exit status of ntpstat command

You can use the exit status (return values) to verify its operations from a shell script or command line itself:

  • If exit status 0 – Clock is synchronised.
  • exit status 1 – Clock is not synchronised.
  • exit status 2 – If clock state is indeterminant, for example if ntpd is not contactable.

Type the command as follows:
$ ntpstat
Sample outputs:

synchronised to NTP server (149.20.54.20) at stratum 3 
   time correct to within 42 ms
   polling server every 1024 s

Use the echo command to display exit status of ntp client:
$ echo $?
Sample outputs:

0

Checking the status of NTP with ntpq command

The ntpq utility program is used to monitor NTP daemon ntpd operations and determine performance. The program can be run either in interactive mode or controlled using command line arguments. Type the following command on your Linux or Unix-based system:
$ ntpq -pn
OR
$ ntpq -p
Sample outputs:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*dione.cbane.org 204.123.2.5      2 u  509 1024  377   51.661   -3.343   0.279
+ns1.your-site.c 132.236.56.252   3 u  899 1024  377   48.395    2.047   1.006
+ntp.yoinks.net  129.7.1.66       2 u  930 1024  377    0.693    1.035   0.241
 LOCAL(0)        .LOCL.          10 l   45   64  377    0.000    0.000   0.001

* the source you are synchronized to (syspeer). The above is an example of working ntp client. Where,

  1. -p : Print a list of the peers known to the server as well as a summary of their state.
  2. -n : Output all host addresses in dotted-quad numeric format rather than converting to the canonical host names.

Another reliable source is running the following command:
$ ntpq -c rv
Look for the leap code as follows:
Linux Verify NTP is Working Or Not
So leap code 0 (leap_none) means normal synchronized state. And leap code 3 (leap_alarm) means NTP wasnever synchronized. Here is a sample outputs:
How to check NTP is working?

A note about timedatectl command

If you are using systemd based system, run the following command to check the service status
# timedatectl status
Sample outputs:

Is my NTP (systemd-timesyncd) Working?

Is my NTP (systemd-timesyncd) Working?

systemd-timesyncd configuration

If NTP enabled is set to No. Try configuring by editing /etc/systemd/timesyncd.conf file as follows:
# vi /etc/systemd/timesyncd.conf
Append/edit [Time] as follows i.e. add time servers or change the provided ones, uncomment the relevant line and list their host name or IP separated by a space (default from my Debian 8.x server):

[Time]
Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org

Save and close the file. Finally, start and enable it, run:
# timedatectl set-ntp true
# timedatectl status

Sample outputs:

                      Local time: Mon 2019-09-30 18:25:38 IST
                  Universal time: Mon 2019-09-30 12:55:38 UTC
                        RTC time: Mon 2019-09-30 12:55:38
                       Time zone: Asia/Kolkata (IST, +0530)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

The above is easy way to verify NTP is working on Linux.

Conclusion

You learned how to verify that your NTP configuration is working properly. Now you know how to check the status of your date and time, synchronized with upstream time servers. For more info see ntpd docs here.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
10 comments… add one
  • Philippe Petrinko Mar 26, 2010 @ 12:46

    Informative and simple. Thanks Vivek

  • Wes Feb 18, 2014 @ 22:07

    You should fix this typo:

    >> “exit status 1 – Cock is not synchronised.”

    • 🐧 Nix Craft Feb 19, 2014 @ 6:26

      Thanks for the heads up. The faq has been updated.

  • Philippe Petrinko Feb 19, 2014 @ 7:38

    Hi Vivek,

    Recommend readings link seems to be broken:

    man ntpq

    I guess you may want to recommend:
    1. https://en.wikipedia.org/wiki/Ntpd
    2. http://www.eecis.udel.edu/~mills/ntp/html/ntpq.html
    3. http://support.ntp.org/bin/view/Support/TroubleshootingNTP

    • 🐧 Nix Craft Feb 19, 2014 @ 12:23

      Hi Philippe,

      The post has been updated. As always, I appreciate your feedback and time :)

  • David Dec 1, 2015 @ 12:06

    If you’re using chrony rather than ntpd (chrony is the default on Fedora), the command to check is “chronyc sources” and gives output like this:

    210 Number of sources = 1
    MS Name/IP address         Stratum Poll Reach LastRx Last sample
    ===============================================================================
    ^* ntp.yoinks.net               4   8   377   163    -40us[  -46us] +/-  108ms
    
  • xerito Mar 17, 2016 @ 22:36

    thank you very much.

  • Roberto Oct 10, 2016 @ 15:25

    Worked like a charm.. Thanks!

  • amir Mar 23, 2017 @ 18:18

    nope:
    bash: ntpq: command not found

  • Geldrin Apr 28, 2017 @ 12:39

    Strange, none of the above mentioned tools are available on Debian Jessie. Is this normal?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.