Time Date and Timesync using Chronyd

redhat

Every system has a clock and is a critical component of the Operating System. It keep the time, which is used for various proposes such as:

  • Running automated jobs as configured intervals
  • Marking timestamp on file properties
  • Keeping track of when certain operations were made, and marking the time on entries in the log file related to it.
  • Ensuring synchronous activities between systems are managed properly
  • etc. …

 

The commonly command and its switches used to view and manage the time configured in a system are as follows:

[root@centos9vm ~]# timedatectl
=========
Local time: Sun 2024-06-30 06:48:38 IST
Universal time: Sun 2024-06-30 01:18:38 UTC
RTC time: Sun 2024-06-30 01:18:38
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
==========

The below command will help to identify the Time Zones that can be configured on this system

[root@centos9vm ~]# tzselect

===== ===
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, “coord”, or “TZ”.
1) Africa 2) Americas 3)……

Enter the selection: 2
Please select a country whose clocks agree with yours.
1) Anguilla  2)…. 49) United States

Enter the selection: 49
Please select one of the following timezones.
1) Eastern (most areas)  ….  29) Hawaii

Enter the selection: 1
The following information has been given:

United States
Eastern (most areas)
Therefore TZ=’America/New_York’ will be used.
===== ==

Now let us configure a new TimeZone using the timedatectl command

[root@centos9vm ~]# timedatectl set-timezone America/New_York

If the timedatectl command shows a line as below, that means NTP time synchronization is enabled

NTP service: active

Now let us try to change the date configured in the system. For this we will have to disable NTP time synchronization first

[root@centos9vm ~]# timedatectl set-ntp false
[root@centos9vm ~]# timedatectl set-time 2022-10-22

[root@centos9vm ~]# timedatectl
Local time: Sat 2022-10-22 00:00:09 EDT
………
==== ==

[root@centos9vm ~]# timedatectl set-ntp true
[root@centos9vm ~]# timedatectl
Local time: Sun 2024-06-30 05:21:27 EDT
====== ===

As the NTP is enabled, let us see the NTP server that is used

[root@centos9vm ~]# chronyc sources -v

====== ===
MS Name/IP address Stratum Poll Reach LastRx Last sample

^+ time.cloudflare.com 3 6 377 35 -3621us[-3542us] +/- 48ms
^- ntp.qntmnet.com 2 6 377 37 -7921us[-7843us] +/- 104ms
===== ==

The NTP server is configured in the file /etc/chrony.conf

[root@centos9vm ~]# cat /etc/chrony.conf

=====
pool 2.centos.pool.ntp.org     iburst
=======