NTP stands for Network Time Protocol, which synchronizes clocks between computer systems over the Network. An NTP server keeps all servers in an organization in sync to perform time-based jobs at the exact time. The NTP client synchronizes its time with the NTP server.

We have written an article about NTP server and client installation and configuration. If you would like to view these articles, please navigate to the links below.

  • How do I install and configure the NTP server and client on Linux?
  • How do I install and configure Chrony as the NTP client?

I assume that you have set up the NTP server and NTP client using the above link. Now, how do I verify that the NTP Settings are working properly?

There are three commands in Linux to verify NTP synchronization. Details are as follows. In this article, we’ll show you how to verify NTP synchronization using all of these commands.

  • ntpq: NTPQ is a standard NTP query program.
  • ntpstat: Displays the network world synchronization status.
  • timedatectlIt controls the system time and date in the systemd system.

Method 1: How do I run the NTPQ command to check the NTP status?

The NTPQ utility is used to monitor the operation of the NTP daemon NTPD and determine performance.

The program can be run in interactive mode or controlled using command-line arguments. It prints out a list of connected peers by sending multiple queries to the server. If NTP is working properly, you will get output similar to the following.

# ntpq -premote refid st t when poll reach delay offset jitter = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * CentOS7.2 daygee 133.243.238.163 2 u 14 64 37 0.686 0.151 16.432Copy the code

Details:

  • -p: Prints a list of peers known to the server and a summary of their status.

Method 2: How do I run the ntpstat command to check the NTP status?

Ntpstat reports the synchronization status of the NTP daemon (NTPD) running on the local computer. If the local system is found to be in sync with the reference time source, nTPSTAT reports the approximate time accuracy.

The ntpstat command returns three status codes based on the NTP synchronization status. Details are as follows.

  • 0: Returns 0 if the clock is synchronized.
  • 1: Returns 1 if the clock is not synchronized.
  • 2: Returns 2 if the clock status is uncertain, for example, when NTPD is unreachable.
# ntpstatSynchronised to NTP server (192.168.1.8) at stratum 3 time correct to within 508 MS polling server every 64 sCopy the code

Method 3: How do I use the timedatectl command to check the NTP status?

The timeDatectl command is used to query and change the system clock and its Settings in systMed.

# timedatectl# timedatectl status

      Local time: Thu 2019-05-30 05:01:05 CDT
  Universal time: Thu 2019-05-30 10:01:05 UTC
        RTC time: Thu 2019-05-30 10:01:05
       Time zone: America/Chicago (CDT, -0500)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2019-03-10 01:59:59 CST
                  Sun 2019-03-10 03:00:00 CDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2019-11-03 01:59:59 CDT
                  Sun 2019-11-03 01:00:00 CST
Copy the code

More skills

Chrony is an alternative NTP client. It synchronizes system clocks faster and with higher time accuracy, which is especially useful for systems that are always offline.

Chronyd is smaller, uses less memory, and only wakes up the CPU when necessary to save more power. It works well even if the network is congested for a long time.

You can use any of the following commands to check Chrony status.

Check the Chrony trace status.

# chronyc trackingReference ID: C0A80105 (CentOS7.2daygeek.com) Stratum: 3 Ref time (UTC) : Thu Mar 28 05:57:27 2019 System time: 0.000002545 seconds slow of NTP time Last offset: +0.001194361 seconds RMS offset: 0.001194361 seconds Frequency: 1.650 PPM fast Residual freq: +184.101 PPM Skew: 2.962 PPM Root delay: 0.107966967 seconds Root dispersion: 1.060455322 seconds Update interval: 2.0 seconds Leap Status: NormalCopy the code

Run the sources command to display information about the current time source.

# chronyc sources210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ^ * CentOS7.2daygeek.com 2 June 17, 62 +36us[+1230us] +/- 1111msCopy the code

Via: www.2daygeek.com/check-verif…

By Magesh Maruthamuthu, lujun9972

This article is originally compiled by LCTT and released in Linux China