Linux Time Synchronization with NTP and Chrony

Time synchronization in Linux ensures that system clocks remain accurate and uniform across distributed environments, which is critical for log integrity, database transactions, and cryptographic authentication. This article explores how Linux manages time between hardware and the kernel, how the Network Time Protocol (NTP) algorithm measures and corrects time discrepancies, and how modern implementations like Chrony and the legacy ntpd daemon actively maintain synchronization.

System Clock vs. Hardware Clock

Linux distinguishes between two primary clocks:

At boot, the kernel reads the RTC to initialize the system clock. Once the OS is running, the system clock takes over. Because physical quartz crystals on motherboards are vulnerable to temperature fluctuations and hardware imperfections, the system clock inevitably drifts from real-world time. Time synchronization software corrects this drift.

The Network Time Protocol (NTP) Mechanism

Linux uses the Network Time Protocol (NTP) to exchange timing information over UDP port 123. NTP organizes time sources into a hierarchical system known as "strata":

To determine the accurate time, an NTP client periodically exchanges timestamped packets with one or more reference servers. Each exchange records four timestamps:

  1. When the client sends the request (\(T_1\)).
  2. When the server receives the request (\(T_2\)).
  3. When the server sends the response (\(T_3\)).
  4. When the client receives the response (\(T_4\)).

Using these values, the client calculates two essential metrics:

By querying multiple servers, the client filters out network jitter and rejects unreliable servers ("falsetickers") to compute a statistically robust time offset.

Correcting the Clock: Slewing vs. Stepping

When a discrepancy is detected, the Linux kernel corrects the system clock using one of two methods:

Chrony vs. NTPd

Linux systems primarily use either the traditional ntpd daemon or the modern chronyd (Chrony) service to automate this process.

Chrony (chronyd)

Chrony is the default time synchronization utility in modern distributions like RHEL, CentOS, Rocky Linux, Fedora, and Debian/Ubuntu variants. Chrony was designed to address the realities of modern compute environments:

The NTP Daemon (ntpd)

The reference implementation of the Network Time Protocol, ntpd, is an older, battle-tested service. It is designed for permanently connected physical servers that require microsecond precision over long periods of stable operation. It prioritizes stability over rapid adjustment, exclusively slewing the clock under normal operations once the initial offset is resolved. Its state is queried using ntpq (e.g., ntpq -p).

Synchronization with the Hardware Clock

To ensure the hardware clock stays accurate while the machine is running, the Linux kernel utilizes "11-minute mode." Whenever the system clock is synchronized by an NTP or Chrony daemon, the kernel automatically writes the accurate system time back to the RTC every 11 minutes. This ensures that subsequent reboots start with an accurate baseline time before network services become available.