How to synchronize time using NTP and set timezone in CentOS/RHEL 7 and 8

Setting local clocks and time zones

Correct synchronized system time is critical for log file analysis across multiple systems. The Network Time Protocol (NTP) is a standard way for machines to provide and obtain correct time information on the Internet. A machine may get accurate time information from public NTP services on the Internet, such as the NTP Pool Project. A high-quality hardware clock to serve accurate time to local clients is another option.

The timedatectl command shows an overview of the current time-related system settings, including current time, time zone, and NTP synchronization settings of the system.

[user@host ~]$ timedatectl
Local time: Fri 2019-04-05 16:10:29 CDT
Universal time: Fri 2019-04-05 21:10:29 UTC
RTC time: Fri 2019-04-05 21:10:29
Time zone: America/Chicago (CDT, -0500)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

A database of time zones is available and can be listed with the timedatectl list-timezones command.

[user@host ~]$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako

Time zone names are based on the public time zone database that IANA maintains. Time zones are named based on continent or ocean, then typically but not always the largest city within the time zone region. For example, most of the US Mountain time zone is America/Denver. Selecting the correct name can be non-intuitive in cases where localities inside the time zone have different daylight saving time rules. For example, in the USA, much of the state of Arizona (US Mountain time) does not have a daylight saving time adjustment at all and is in the time zone America/Phoenix.

The command tzselect is useful for identifying correct zoneinfo time zone names. It interactively prompts the user with questions about the system’s location, and outputs the name of the correct time zone. It does not make any change to the time zone setting of the system. The superuser can change the system setting to update the current time zone using the timedatectl set-timezone command. The following timedatectl command updates the current time zone to America/Phoenix:

[root@host ~]# timedatectl set-timezone America/Phoenix
[root@host ~]# timedatectl
           Local time: Fri 2019-04-05 14:12:39 MST
           Universal time: Fri 2019-04-05 21:12:39 UTC
                 RTC time: Fri 2019-04-05 21:12:39
                Time zone: America/Phoenix (MST, -0700)
 System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Use the timedatectl set-time command to change the system’s current time. The time is specified in the “YYYY-MM-DD hh:mm:ss” format, where either date or time can be omitted. The following timedatectl command changes the time to 09:00:00.

[root@host ~]# timedatectl set-time 9:00:00
[root@serverX ~]$ timedatectl
               Local time: Fri 2019-04-05 09:00:27 MST
           Universal time: Fri 2019-04-05 16:00:27 UTC
                 RTC time: Fri 2019-04-05 16:00:27
                Time zone: America/Phoenix (MST, -0700)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

The timedatectl set-ntp command enables or disables NTP synchronization for automatic time adjustment. The option requires either a true or false argument to turn it on or off. The following timedatectl command turns on NTP synchronization.

[root@host ~]# timedatectl set-ntp true