How to Use the Command 'chronyc' (with Examples)
- Linux
- December 17, 2024
The chronyc
command serves as a command-line interface to interact with the Chrony NTP (Network Time Protocol) daemon. Chrony plays a critical role in maintaining precise time synchronization across computer systems. This is especially important for distributed systems, where time consistency can be crucial for correct operation. The chronyc
command allows users to query various aspects of the NTP daemon’s state and performance, offering insights into how time synchronization is being managed.
Start chronyc
in Interactive Mode
Code:
chronyc
Motivation:
Running chronyc
in interactive mode is useful for system administrators and network engineers who need to execute multiple commands in a chronological order without having to repeatedly execute chronyc
from the command line. This mode provides a flexible environment where users can quickly issue a series of commands to monitor and adjust time settings, enhancing efficiency during troubleshooting or configuration tasks.
Explanation:
By simply entering chronyc
, you initiate the program in a state that waits for further commands. The lack of any additional arguments signals the command to operate in an interactive manner, allowing users to input subsequent subcommands manually.
Example Output:
chronyc>
The prompt indicates that the session is ready for additional commands.
Display Tracking Stats for the Chrony Daemon
Code:
chronyc tracking
Motivation:
Checking the tracking statistics is critical for verifying how accurately your system’s clock is synchronized with the network time sources. This usage scenario is optimum for determining the offset of the system’s clock, the frequency error, the estimated root delay, and other important metrics that provide a snapshot of the clock state in relation to its time sources.
Explanation:
The tracking
argument requests a report summarizing the status of the NTP synchronization. It includes metrics of how well Chrony is maintaining system time, helping diagnose potential time synchronization issues.
Example Output:
Reference ID : C0A80101 (192.168.1.1)
Stratum : 3
Ref time (UTC) : Tue Oct 24 14:23:45 2023
System time : 0.000087342 seconds fast of NTP time
Frequency : 7.892 ppm fast
Print the Time Sources that Chrony is Currently Using
Code:
chronyc sources
Motivation:
Knowing which time sources are actively being used by your Chrony NTP daemon can be vital for ensuring that these sources are reliable and properly configured. This information assists in diagnosing synchronization issues and verifying the integrity of the time sources.
Explanation:
By invoking sources
, you receive a list of all detected time sources that Chrony is utilizing to sync the system clock. It outlines each source’s status and other useful attributes like reachability and delay.
Example Output:
210 Number of sources = 2
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* time.google.com 2 6 377 35 -2079us[ -941us] +/- 13ms
^- ntp.example.com 3 6 377 30 +46ms[+2388us] +/- 33ms
Display Stats for Sources Currently Used by Chrony Daemon as a Time Source
Code:
chronyc sourcestats
Motivation:
This command is deployed when administrators need detailed statistical insights into each active time source’s performance. Such statistics can reveal patterns over time, like jitter and latency, aiding in the identification and troubleshooting of underperforming NTP servers.
Explanation:
The sourcestats
option provides a deeper look beyond the basic sources
command, highlighting averages and RMS of observed values, providing a historical context to the source’s clock data.
Example Output:
210 Number of sources = 2
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
time.google.com 8 4 11 -0.006 0.008 +10us 11us
ntp.example.com 9 4 34 0.003 0.012 -287us 23us
Step the System Clock Immediately, Bypassing Any Slewing
Code:
chronyc makestep
Motivation:
There are situations where an immediate step adjustment of the system clock is imperative, such as after correcting a misconfigured server or after an extended period of disconnected operation. makestep
provides a powerful mechanism to instantaneously correct potentially significant time discrepancies without waiting for gradual slewing.
Explanation:
The makestep
option instructs Chrony to make a large adjustment to the system clock immediately, resetting it to align precisely with the current NTP reference time. The use of makestep
is especially useful for correcting major offsets.
Example Output:
200 OK
This message confirms that the system clock has been successfully stepped.
Display Verbose Information About Each NTP Source
Code:
chronyc ntpdata
Motivation:
When an in-depth analysis of NTP sources is required, ntpdata
reveals extensive details such as timings, delays, and status flags for each server. This information is incredibly useful for pinpointing more subtle synchronization issues and understanding the reliability of each time source.
Explanation:
ntpdata
retrieves verbose, low-level diagnostic data about each configured time source, offering deeper insights into the timing data being measured and processed by the NTP daemon.
Example Output:
Name/IP Address Stratum Ref ID LastRX Delta/MS Jitter/MS
time.google.com 2 .GPS. 12m -0.123 0.002
ntp.example.com 3 .PPS. 6m +0.045 0.011
Conclusion
The chronyc
command offers a suite of tools for querying and controlling the Chrony NTP daemon, making it indispensable for managing time synchronization in modern network environments. Each use case is structured to address different aspects of time management, from basic to advanced analysis, granting administrators the necessary control and insight needed to maintain accurate and reliable time across systems.