NTP stand for Network Time Protocol, which synchronizes the clock between computer systems over the network.
NTP server keep all the servers in-sync with accurate time to perform time based jobs in an organization. NTP client will synchronize its clock to the network time server.
We already wrote an article about NTP Server, Client installation and configuration. If you would like to check these articles, navigate to the following links:
- How to Install and Configure NTP Server and NTP Client In Linux?
- How to Install and Configure Chrony as NTP Client?
I’m assuming that we have setup the NTP server and NTP client by referring to the above links. In this guide, we will show you how to verify whether the NTP setup is working or not?
NTP sync status can be verified using the following three commands:
ntpq:
ntpq is standard NTP query program.ntpstat:
It shows network time synchronization status.timedatectl:
It controls the system time and date in systemd system.
Let’s understand each of the commands in detail.
Method-1: Checking the status of NTP using ntpq command
The ‘ntpq’ command is used to monitor NTP daemon and determine the performance, which can be identified by querying the NTP servers running on the host.
It runs either in interactive mode or by using command-line arguments. It prints a list of connected peers by sending multiple queries to the server.
If NTP is working properly, you should get the below output:
# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *CentOS7.2daygee 133.243.238.163 2 u 14 64 37 0.686 0.151 16.432
Details:
- -p: Print a list of the peers known to the server as well as a summary of their state.
- remote: Remote NTP server
- st: The stratum of the remote peer
- t: Type of the peer (local, unicast, multicast or broadcast)
- when: Time the last packet was received, the polling interval (seconds)
- poll: How frequently to query server (in seconds)
- reach: Octal bitmask of success or failure of last 8 queries.
- delay: Network round trip time (in milliseconds)
- offset: Difference between local clock and remote clock (in milliseconds)
- jitter: Difference of successive time values from server
Method-2: How to check NTP status using ntpstat command
ntpstat will report the synchronization state of the NTP daemon (ntpd) running on the local machine.
If the local system is found to be synchronized to a reference time source, ntpstat will report the approximate time accuracy.
The ntpstat command returns three types of status codes based on the NTP sync as mentioned below:
0:
It returns 0, if clock is synchronised.1:
It returns 1, if clock is not synchronised.2:
It returns 2, if clock state is indeterminant, for example if ntpd is not contactable.
# ntpstat synchronised to NTP server (192.168.1.8) at stratum 3 time correct to within 508 ms polling server every 64 s
Method-3: Checking NTP sync status with timedatectl command
timedatectl command is used to query and change the system clock and its settings in systemd system:
# timedatectl or # 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
Bonus Tips:
Chrony is replacement of NTP client. It can synchronize the system clock faster with better time accuracy and it can be very much useful for the systems which are not online all the time.
Chronyd is smaller in size, it uses less system memory and it wakes up the CPU only when necessary, which is better for power saving.
It can perform well, even when the network is congested for longer periods of time. You can use any of the below commands to check Chrony status:
# chronyc tracking Reference ID : C0A80105 (CentOS7.wachid.web.id) 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 : Normal
Run the sources command to display information about the current time sources:
# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* CentOS7.wachid.web.id 2 6 17 62 +36us[+1230us] +/- 1111ms
Conclusion
In this guide, you learned how to check NTP synchronize status on linux using three different commands.
If you have any questions, feel free to leave a comment. We will get back to you as soon as possible.