Linux Time Sync: Why Chrony is the Modern Standard Over NTP

Linux tutorial - IT technology blog
Linux tutorial - IT technology blog

Chasing Ghosts in Your Log Files

There is nothing more frustrating than chasing a ghost in your logs. Imagine debugging a database error across a three-node cluster. You check Server A, then jump to Server B to find the matching event. To your surprise, Server B’s logs claim the event happened two seconds before it even started on Server A. This discrepancy makes tracing transactions or security events a nightmare.

I recently dealt with a production outage caused by a mere 500ms drift. That tiny gap caused JSON Web Tokens (JWT) to expire prematurely because the authentication server was slightly ahead of the application server. These “time travel” bugs are common in distributed systems. They lead to data corruption, failed backups, and broken authentication protocols.

How Linux Clocks Lose Their Way

Before fixing the drift, we need to distinguish between the two clocks your server manages:

  • The Hardware Clock (RTC): This is a battery-backed clock on the motherboard. It keeps time even when the power is off.
  • The System Clock: This is maintained by the Linux kernel. It provides the timestamps used by your applications, logs, and cron jobs.

Hardware isn’t perfect. The quartz oscillators in most motherboards are sensitive to temperature and age. A typical server can drift by 10 to 20 seconds per month without external synchronization. Virtualization makes this worse. In AWS or GCP environments, the CPU is shared. The “ticks” the system clock relies on can be delayed or dropped entirely, causing rapid drift.

While the standard Network Time Protocol (NTP) was designed decades ago, it struggles with modern challenges. It often fails to handle intermittent network connections or systems that enter sleep mode. Chrony was built to solve these specific issues.

NTP vs. Chrony: The Better Choice

NTP is the protocol, but the software implementing it has changed. For years, ntpd was the default choice. However, modern distributions like Ubuntu, RHEL, and Fedora have moved to chronyd (Chrony). Here is why the switch matters:

  • Rapid Synchronization: Chrony syncs the clock in seconds rather than minutes. This is a lifesaver for cloud instances that spin up and down frequently.
  • Drift Compensation: Chrony calculates the exact rate at which your clock gains or loses time. It continues to correct the clock even if the network goes down.
  • Virtualization Awareness: It handles the “jitter” of virtualized hardware much more gracefully than the old NTP daemon.

On my production Ubuntu 22.04 nodes, switching to Chrony eliminated the “stepped” time jumps that used to crash our sensitive background tasks. The system now adjusts time smoothly by speeding up or slowing down the clock slightly.

Practical Setup: Implementing Chrony

Chrony is likely already in your package manager. Follow these steps to get it running correctly.

1. Install the Package

Remove any legacy NTP services first to prevent conflicts. Then, install Chrony.

# For Ubuntu/Debian
sudo apt update && sudo apt install chrony -y

# For RHEL/CentOS/AlmaLinux
sudo dnf install chrony -y

2. Configure Reliable Upstream Servers

Your configuration lives at /etc/chrony/chrony.conf (Ubuntu) or /etc/chrony.conf (RHEL). Open it with your editor:

sudo nano /etc/chrony/chrony.conf

Find the lines starting with pool. For the best results, use servers geographically close to your data center. If your servers are in North America, use these:

# Use public servers from the pool.ntp.org project.
pool 0.north-america.pool.ntp.org iburst
pool 1.north-america.pool.ntp.org iburst
pool 2.north-america.pool.ntp.org iburst

The iburst directive is crucial. It tells Chrony to send a burst of requests upon startup, ensuring your server finds the correct time within seconds.

3. Restart the Service

sudo systemctl enable --now chrony
sudo systemctl restart chrony

Verifying Your Sync Health

Don’t just assume it’s working. Chrony comes with a handy command-line utility called chronyc for checking your timing health.

Review Time Sources

Check your connection to upstream servers with this command:

chronyc sources -v

Look for the ^* symbol. This means Chrony has selected that server as the primary source. If you see ^?, the server is unreachable. A ^x indicates a “falseticker”—a server whose time is too far off to be trusted.

Monitor Clock Drift

To see how well your local clock is performing, check the tracking data:

chronyc tracking

Focus on the RMS offset. This value represents the long-term average difference between your system and real time. In a healthy setup, this should be in the microsecond or low millisecond range.

The Cloud Exception: AWS and GCP

Cloud providers often offer their own high-precision time sources. For example, AWS provides the Amazon Time Sync Service at 169.254.169.123. This internal IP offers incredibly low latency, usually under 1ms. If you are on EC2, add this line to the top of your config:

# Use the local AWS time source for sub-millisecond accuracy
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4

Wrapping Up

Time synchronization isn’t just about having the right clock on your taskbar. It is a fundamental requirement for security, logging, and database integrity. By moving to Chrony and monitoring your offsets, you protect your infrastructure from the subtle, damaging effects of clock drift. Check your chronyc tracking today; your logs will thank you.

Share: