← Back to list

Chrony — Your Reliable Timekeeper

A step-by-step guide to installing, configuring, and optimizing Chrony for reliable time synchronization on your Linux systems.

Tim Reddish · 2024-05-25 16:35 · 0 claps · 8.3 min read paywalled
#chrony #linux #time-synchronization #timesync
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Chrony — Your Reliable Timekeeper

A step-by-step guide to installing, configuring, and optimizing Chrony for reliable time synchronization on your Linux systems.

Photo by Lukas Tennie on Unsplash

Photo by Lukas Tennie on Unsplash

Introduction

In the fast-paced world of Linux systems, where milliseconds can make a difference, accurate time synchronization is paramount. Whether ensuring the consistency of logs, orchestrating distributed tasks, or meeting regulatory compliance requirements, a reliable Network Time Protocol (NTP) implementation is indispensable.

While ntpd has long been the go-to solution, Chrony, a versatile and lightweight alternative, has steadily gained popularity. This article explores the intricacies of Chrony, guiding you through its installation, configuration, and management to master time synchronization on your Linux machines.

Chrony offers several compelling advantages over traditional NTP daemons:

  • Faster Convergence: Chrony adjusts system time more rapidly, particularly crucial in dynamic environments where clock drifts are frequent.
  • Lower Resource Consumption: Its lightweight nature makes it an ideal choice for resource-constrained systems or embedded devices.
  • Robustness to Network Fluctuations: Chrony gracefully handles intermittent network connectivity, ensuring accurate time even with sporadic access to NTP servers.

Whether you’re a seasoned system administrator seeking a more efficient timekeeping solution or a Linux enthusiast eager to delve into the nuances of NTP, this guide equips you with the knowledge to harness Chrony’s capabilities fully. By the end, you’ll be well-versed in setting up Chrony, configuring it to suit your specific needs, and troubleshooting potential issues.

Installation

Getting Chrony on Your System

Installing Chrony is a breeze, thanks to its widespread availability in most Linux distribution repositories. Here’s how to install it on some of the major distributions:

Debian / Ubuntu:

sudo apt update
sudo apt install chrony

Fedora / CentOS / RHEL:

sudo dnf update
sudo dnf install chrony

Arch Linux / Manjaro:

sudo pacman -Syu
sudo pacman -S chrony

Other Distributions:

If your distribution isn’t listed here, simply use your package manager’s search function to find and install the chrony package.

Verifying Installation

Once installed, you can quickly verify that Chrony is present and ready to go:

chronyc -v

This command should output the Chrony version and other details, confirming successful installation.

chronyc -v

chronyc -v

With Chrony installed, you’re now ready to embark on the journey of configuring it to keep your system time in perfect sync.

Basic Configuration

Setting Up Chrony for Time Synchronization

The heart of Chrony’s configuration lies in the /etc/chrony.conf file, typically located in your system’s /etc directory. Let’s unravel the essential directives that get Chrony up and running.

Understanding the Configuration File

The /etc/chrony.conf file contains numerous directives, each influencing Chrony’s behavior. For basic setup, we’ll focus on a few key ones.

**server : **This directive specifies the NTP servers you want Chrony to synchronize with. For redundancy and reliability, it’s recommended to use multiple servers. Here’s an example utilizing Google’s public NTP servers.

server time1.google.com iburst
server time2.google.com iburst
server time3.google.com iburst
server time4.google.com iburst

The iburst option sends a burst of packets initially for faster synchronization.

**pool : **Alternatively, you can use NTP pools, which provide a group of servers for automatic selection.

pool time.google.com iburst

**driftfile : **This directive points to a file where Chrony stores clock drift data. This data is essential for maintaining accuracy between synchronizations.

driftfile /var/lib/chrony/drift

For Debian / Ubuntu based systems the main configuration file, /etc/chrony/chrony.conf is in a slighly different location.

Starting and Enabling Chrony

With the essential configuration in place, you can start the Chrony daemon and enable it to start automatically at boot:

sudo systemctl start chronyd
sudo systemctl enable chronyd

Verifying Time Synchronization

You can use the chronyc commands to check if Chrony is successfully synchronizing with the specified NTP servers:

chronyc sources -v

chronyc sources -v

chronyc sources -v

This command displays the status of each server, indicating whether it’s reachable and being used for synchronization.

By completing these basic configuration steps, you’ve taken the first strides toward ensuring accurate timekeeping on your Linux system with Chrony. In the next section, we’ll delve into advanced configuration options, empowering you with greater control and flexibility.

Advanced Configuration

Fine-Tuning Chrony for Your Needs

While the basic configuration gets Chrony running, delving into advanced options allows you to tailor its behavior precisely to your requirements. Let’s explore some of the powerful directives that give you greater control.

Time Correction and Adjustment

**makestep** : This directive governs how Chrony corrects time offsets. By default, Chrony gradually adjusts time to avoid abrupt changes that could disrupt applications. However, you can specify an offset limit and a number of attempts for Chrony to make larger adjustments, if needed.

makestep 10 3  # Allows up to 10 seconds jump in 3 attempts

**smoothtime** : If you have a very unstable clock source, this option gradually adjusts the frequency instead of the offset. This can provide smoother time adjustments.

smoothtime 0.001  # Adjust the system clock's frequency by up to 0.001 PPM (parts per million) per second

Reference Clocks and Local Stratum

**refclock** : This directive allows you to configure reference clocks, such as GPS receivers or radio clocks, as a source of accurate time. Consult the Chrony documentation for specific configuration instructions for your reference clock.

**local stratum 10** : Makes your Chrony server act as a reference clock (stratum 10) for other clients, even if it doesn’t have a reliable external time source. Use this option with caution, as it can propagate inaccurate time if not configured carefully.

Access Control and Security

**allow and deny** : These directives let you control access to your Chrony server. You can specify IP addresses or subnets that are allowed or denied to request time from your server.

allow  192.168.1.0/24  # Allow clients from the local network
deny   10.0.0.0/8      # Deny clients from another network

Logging and Debugging

**log** : This directive configures logging for Chrony. You can specify which events to log, the log level (e.g., measurements , statistics , tracking ) and the log file location.

logdir /var/log/chrony
log    measurements statistics tracking

Client-Server Configuration

To set up a Chrony server to provide time to other machines, uncomment the allow directive in the server’s configuration file. Clients can then be configured to use the server’s IP address or hostname with the server directive.

Network Time Security (NTS)

NTS adds authentication and encryption to NTP communication. By configuring keys and trust relationships, you can significantly enhance the security of your time synchronization setup.

By understanding and utilizing these advanced configuration options, you gain granular control over Chrony’s behavior, tailoring it perfectly to your environment and security requirements. Remember to refer to the official Chrony documentation for in-depth explanations of all available directives and options.

Chrony Management

Monitoring, Control, and Troubleshooting

Once Chrony is configured and running, actively managing and monitoring its operation is essential to maintain accurate timekeeping. This section equips you with the tools and techniques to oversee Chrony’s performance and troubleshoot any potential issues.

The chronyc Command

Your Control Center

The chronyc command-line utility provides a wealth of information and control over Chrony. Here are some key commands and their functions.

chronyc sources -v : Displays detailed information about the NTP servers Chrony is using, including their stratum level, reachability, and synchronization status.

chronyc tracking : Shows how Chrony is adjusting your system’s clock to keep it synchronized with the reference time. This includes information about the current time offset, frequency adjustment, and estimated error.

chronyc activity : Provides a summary of Chrony’s activity, including the number of NTP packets received and sent, and any recent events like clock adjustments.

chronyc sourcestats : Displays statistics about the reliability and accuracy of each NTP server being used.

manual and drift : Allow you to manually adjust the system clock or clock drift if necessary. Use these commands with caution, as incorrect adjustments can disrupt system operations.

Troubleshooting Common Issues

If Chrony isn’t synchronizing time correctly, here are some common troubleshooting steps:

  • Check Firewall Rules: Ensure that your firewall is not blocking UDP traffic on port 123, which is used for NTP communication.
  • Verify Network Connectivity: Ensure your system can reach the configured NTP servers. You can use the ping command or a network diagnostic tool to test connectivity.
  • Examine Log Files: Chrony logs events and errors to system log files (usually /var/log/chrony). Inspect the logs for clues about potential issues.
  • Restart Chrony: If all else fails, restarting the Chrony service can sometimes resolve problems.

Additional Tips for Monitoring and Maintenance

  • Regularly Check Status: Periodically use chronyc sources -v and chronyc tracking to monitor Chrony’s synchronization status and ensure it’s working correctly.
  • Monitor Log Files: Set up log monitoring or alerts to detect potential problems early.
  • Use Monitoring Tools: Consider using system monitoring tools that can track Chrony’s performance and send alerts if any anomalies are detected.
  • Review Configuration: If you experience persistent issues, review your Chrony configuration file for any errors or misconfigurations.

By proactively managing and monitoring Chrony, you can ensure that your Linux system’s time remains accurate and reliable, contributing to the overall stability and efficiency of your operations.

Best Practices

Ensuring Accurate and Secure Timekeeping with Chrony

To harness the full potential of Chrony and maintain consistently accurate time on your Linux systems, adhering to best practices is crucial. Here’s a compilation of recommendations and tips to optimize your Chrony configuration:

Selecting Optimal NTP Servers

  • Stratum Levels: Prioritize lower stratum servers, as they are closer to the reference clock and generally more accurate. Aim for servers with stratum 1 or 2 whenever possible.
  • Geographical Proximity: Choose servers geographically closer to your location to minimize network latency and potential synchronization delays.
  • Public vs. Private Servers: Consider using a combination of public NTP pools (like pool.ntp.org) and private servers (if available within your organization) for redundancy and resilience.

Network Considerations

  • Firewall Configuration: Ensure that your firewall allows outbound UDP traffic on port 123, which is used for NTP communication.
  • Dedicated Network Interface: For critical systems, consider using a dedicated network interface for time synchronization to isolate it from other network traffic and potential disruptions.

Security Measures

  • Network Time Security (NTS): Strongly recommended to enable NTS to authenticate and encrypt NTP traffic, mitigating the risk of spoofing and tampering.
  • Firewall Restrictions: Limit access to your Chrony server using the allow and deny directives, allowing only trusted clients to synchronize time.

Monitoring and Maintenance

  • Regular Status Checks: Routinely use chronyc sources -v and chronyc tracking to monitor synchronization status and identify any potential issues.
  • Log Monitoring: Set up log monitoring or alerts to detect anomalies or errors in Chrony’s operation.
  • Configuration Reviews: Periodically review your Chrony configuration file to ensure it aligns with your current requirements and security best practices.

Additional Tips

  • Hardware Timestamping: If your network interface card supports hardware timestamping, enable it in Chrony for improved accuracy.
  • Leap Second Smearing: Enable leap second smearing to avoid sudden jumps in time when leap seconds are introduced.
  • Experiment and Fine-Tune: Don’t hesitate to experiment with different configuration options to find what works best for your specific setup and requirements.

By following these best practices, you can maximize Chrony’s effectiveness, ensure accurate timekeeping, and enhance the security of your time synchronization infrastructure.

Remember that time is a critical resource in any computing environment, and Chrony, when configured correctly, provides a robust and reliable solution for maintaining it.

Conclusion

As we’ve journeyed through the intricacies of Chrony, it’s clear that this versatile time synchronization daemon is a worthy successor to traditional NTP solutions. With its fast convergence, lightweight footprint, and robust handling of network fluctuations, Chrony empowers you to maintain precise timekeeping on your Linux systems.

By meticulously configuring Chrony, leveraging its advanced options, and adhering to best practices, you ensure the consistency of logs, the coordination of distributed tasks, and the overall reliability of your infrastructure. Whether you’re operating a single server or managing a vast network, Chrony provides the tools you need to keep your digital clocks ticking in perfect harmony.

As you venture forth, remember that the Chrony project and its active community offer a wealth of resources, including comprehensive documentation and support forums. Don’t hesitate to explore these resources and fine-tune your Chrony configuration to perfectly align with your unique needs.

In the ever-evolving landscape of Linux system administration, Chrony stands as a testament to the power of open-source innovation, delivering a robust and efficient solution for one of the most fundamental aspects of computing: accurate timekeeping.


메타데이터
post_id
96c026df84d8
slug
chrony-your-reliable-timekeeper-96c026df84d8
url
https://medium.com/@timred/chrony-your-reliable-timekeeper-96c026df84d8
canonical_url
https://medium.com/@timred/chrony-your-reliable-timekeeper-96c026df84d8
author_url
https://medium.com/@timred
status
ok
fetched_at
2026-07-23 18:53:52