Maintain Accurate System Time with timedatectl and chronyd
In this step, you will learn how to maintain accurate system time using the timedatectl command and understand the role of the chronyd service. Accurate timekeeping is crucial for logging, security, and many network services.
1. Using timedatectl to manage system time and time zones:
The timedatectl command provides an overview of the current time-related system settings, including the local time, universal time (UTC), RTC time, time zone, and NTP synchronization status.
Let's check the current time settings of your system:
timedatectl
You should see output similar to this (the exact time and date will reflect your current system time):
Local time: Sun 2025-06-15 21:46:11 EDT
Universal time: Mon 2025-06-16 01:46:11 UTC
RTC time: Mon 2025-06-16 01:46:10
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
You can list all available time zones using the list-timezones option:
timedatectl list-timezones | less
Press q to exit less. The time zones are named based on the Internet Assigned Numbers Authority (IANA) time zone database, typically by continent/ocean and then the largest city.
To change the system's time zone, you use the set-timezone option. For example, let's change the time zone to America/Phoenix. You need sudo privileges for this.
sudo timedatectl set-timezone America/Phoenix
Now, verify the change:
timedatectl
You should see the time zone updated to America/Phoenix.
You can also manually set the system's current time using the set-time option. The format is "YYYY-MM-DD hh:mm:ss", but you can omit the date or time. Let's set the time to 09:00:00 (for the current date).
sudo timedatectl set-time 09:00:00
Verify the time change:
timedatectl
Finally, the set-ntp option enables or disables NTP synchronization for automatic time adjustment. It takes true or false as an argument. Let's disable NTP synchronization for a moment (we will re-enable it later).
sudo timedatectl set-ntp false
Verify the NTP service status:
timedatectl
You should see NTP service: inactive.
2. Understanding and configuring the chronyd service:
The chronyd service is a daemon that keeps the system's Real-Time Clock (RTC) accurate by synchronizing it with Network Time Protocol (NTP) servers. It's the default NTP client in Red Hat Enterprise Linux.
The configuration file for chronyd is /etc/chrony.conf. By default, it uses public NTP servers. In a real-world scenario, you might configure it to use internal NTP servers.
Let's view the default chrony.conf file.
cat /etc/chrony.conf
You will see lines starting with server or pool, which define the NTP sources. The iburst option is recommended as it takes four measurements quickly for more accurate initial synchronization.
The stratum of an NTP time source indicates its quality. A stratum 0 is a reference clock, stratum 1 is directly attached to a reference clock, and stratum 2 synchronizes from a stratum 1 server.
Since systemctl is not available in this container environment, we cannot directly restart chronyd to apply configuration changes. However, we can simulate the configuration change by modifying the file.
Let's re-enable NTP synchronization using timedatectl.
sudo timedatectl set-ntp true
Verify the NTP service status again:
timedatectl
You should see NTP service: active.
The chronyc command acts as a client to the chronyd service. You can use it to monitor the synchronization status. The chronyc sources command shows the current time sources and their synchronization status.
chronyc sources -v
The output will show details about the NTP sources. The asterisk * in the S (Source state) field indicates the source that chronyd is currently synchronized to.
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 100.100.61.88 1 5 377 16 +1824us[+2180us] +/- 85ms
...output omitted...
This output confirms that your system is actively synchronizing its time with an NTP server.