How to use the command chronyc (with examples)
- Linux
- December 25, 2023
The chronyc
command is used to query the Chrony NTP (Network Time Protocol) daemon. It provides various options to display information about the system clock, NTP sources, tracking stats, and more. This article will illustrate each of these use cases with examples.
Use case 1: Start chronyc
in interactive mode
Code:
chronyc
Motivation: Starting chronyc
in interactive mode allows you to directly interact with the Chrony NTP daemon and execute commands without the need to repeatedly type chronyc
before each command. It provides a more convenient and efficient way to query and manage the Chrony daemon.
Explanation: The chronyc
command without any arguments starts the chronyc
utility in interactive mode. This opens a command prompt where various commands can be executed to query and control the Chrony daemon.
Example output:
chronyc version 4.0
chronyc>
Use case 2: Display tracking stats for the Chrony daemon
Code:
chronyc tracking
Motivation: Displaying tracking stats for the Chrony daemon allows you to monitor the system clock’s synchronization and accuracy with the configured NTP sources. This information is crucial for ensuring precise timekeeping and can be useful in troubleshooting any time synchronization issues.
Explanation: The chronyc tracking
command retrieves tracking statistics for the system clock and displays information such as the current time offset, estimated error, and tracking mode.
Example output:
Reference ID : 0123456789 (server.example.com)
Stratum : 2
Ref time (UTC) : Tue Aug 31 10:32:45 2021
System time : 0.000984803 seconds slow of NTP time
Last offset : -0.000123456 seconds
RMS offset : 0.000654321 seconds
Frequency : 6.789 ppm fast
Residual freq : +0.001598825 ppm
Skew : 0.123 ppm
Root delay : 0.123456 seconds
Root dispersion : 0.109876 seconds
Update interval : 64.738 seconds
Leap status : Normal
Use case 3: Print the time sources that Chrony is currently using
Code:
chronyc sources
Motivation: Printing the time sources used by Chrony allows you to identify which NTP servers or peers are being utilized for time synchronization. This information can help troubleshoot issues with specific time sources and ensure a reliable time synchronization setup.
Explanation: The chronyc sources
command retrieves the list of time sources currently being used by Chrony. It displays details such as the source address, reference ID, stratum, delay, and offset.
Example output:
210 Number of sources = 4
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^+ time1.example.com 2 6 377 38 +1230us[+1230us] +/- 45ms
^* time2.example.com 2 6 377 31 -1234us[-1234us] +/- 36ms
^- time3.example.com 3 6 377 24 +1350us[+1350us] +/- 42ms
^? time4.example.com 3 6 377 22 +45ms[ +45ms] +/- 1234ms
Use case 4: Display stats for sources currently used by chrony daemon as a time source
Code:
chronyc sourcestats
Motivation: Displaying source stats for the time sources used by the Chrony daemon provides insights into the performance and reliability of each source. This information can help evaluate the quality of the time sources and aid in troubleshooting time synchronization issues.
Explanation: The chronyc sourcestats
command retrieves statistics for the sources currently used by the Chrony daemon. It displays information such as the source address, first seen time, number of measurements, and the RMS (Root Mean Square) offset.
Example output:
210 Number of sources = 4
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
=======================================================================================
time1.example.com 20 9 1187 -140.123 32.432 -0.064 0.654
time2.example.com 19 7 987 +100.789 12.345 -0.053 0.524
time3.example.com 18 9 344 -1.234 1.234 -0.043 0.324
time4.example.com 15 10 785 -50.678 21.432 -0.032 0.429
Use case 5: Step the system clock immediately, bypassing any slewing
Code:
chronyc makestep
Motivation: Stepping the system clock immediately can be useful in situations where you need to quickly synchronize the system time with a more accurate reference or correct a significant time discrepancy. This command bypasses the gradual adjustment (slewing) normally performed by the Chrony daemon.
Explanation: The chronyc makestep
command instructs the Chrony daemon to step the system clock immediately, disregarding any slewing mechanism. This can result in a sudden correction of the system time, which may cause a time jump.
Example output:
200 OK
Use case 6: Display verbose information about each NTP source
Code:
chronyc ntpdata
Motivation: Displaying verbose information about each NTP source provides detailed data and diagnostics for the selected sources. This information can help in understanding the health, synchronization quality, and other characteristics of the NTP servers or peers.
Explanation: The chronyc ntpdata
command retrieves verbose information about each NTP source currently configured in Chrony. It displays details such as the source address, reference ID, leap status, root distance, dispersion, and NTP version.
Example output:
remote refid st t when poll reach delay offset jitter
==============================================================================
*time1.example.com .GPS. 2 u 32 64 3 8.012 -12.345 1.678
+time2.example.com .PPS. 3 u 12 64 3 10.456 -0.123 4.567
-time3.example.com 192.0.2.1 4 u 22 64 3 25.789 0.987 2.345
-time4.example.com .ATOM. 1 u 142 64 3 18.654 4.321 8.765
Conclusion:
The chronyc
command is a powerful tool for querying and managing the Chrony NTP daemon. By utilizing the various options and arguments provided by chronyc
, administrators can monitor the system clock’s synchronization, inspect time sources, and perform necessary adjustments to ensure accurate timekeeping.