Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Linux / CentOS / CentOS: How to Set Date, Time, TimeZone and NTP Synchronization

May 10, 2023 CentOSLinuxQuestions and Answers

CentOS: How to Set Date, Time, TimeZone and NTP Synchronization

In this article, we’ll show you how to set time, date, timezone, synchronize time with an NTP server and fix typical issues in CentOS Linux.

Contents:
  • Hwclock: Hardware Time Configuration
  • Manual Time Configuration in CentOS
  • How to Set TimeZone in CentOS?
  • Configure CentOS to Sync Time with NTP Time Servers
  • How to Sync Time in CentOS 8 using Chronyd?
  • Common Time Syn Issues in CentOS

There are two types of clocks on the servers: hardware one (real-time clock) that are working even if a server is off and the operating system software clock. The time on these clocks may differ. After starting the operating system, the software clock is based on a hardware one and may be adjusted by the OS.
Most applications use software clock time in their operation.

Hwclock: Hardware Time Configuration

Hwclock is used to check the hardware time in Linux:

  • hwclock --localtime — check hardware time without correction
  • hwclock --utc – displays time if the hardware clock shows UTC time

# hwclock --localtime

2020-10-12 06:12:02.912866-04:00

# hwclock --utc

2020-10-12 02:12:18.915319-04:00

To set hardware time according to the system time, run this command:
# hwclock --systohc
To set the hardware time you want, run the following:
# hwclock --set --date "11 Oct 2020 17:30"

hwclock in linux

Manual Time Configuration in CentOS

In Linux, date or timedatectl tools are used to check and set software time. If you call date without any parameters, it will show the current time on your server:

# date

Sun Oct 11 22:14:54 EDT 2020

If you want to set time manually, you can use date with additional parameters:

# date MMDDhhmm

For example:

# date 10261740

set date centos

To get extended information about the date, time, timezone, synchronization settings, day-light saving time settings (DST), timedatectl is used. It gives more detailed information about time settings on a server.

timedatectl tool in linux centos

Timedatectl also allows to change time:

# timedatectl set-time '2020-10-11 17:51:00'

How to Set TimeZone in CentOS?

To set the time according to your timezone on a CentOS Linux, you can change it manually. To do it, you can use two tools:

  • timedatectl
  • tzdata

To change a time zone using timedatectl, run this command:

# timedatectl set-timezone Canada/Pacific
# date

timedatectl set-timezone

Or you can use tzdata. To use this method, replace the file /etc/localtime with the one you need. The entire list of time zones is located in /usr/share/zoneinfo/ directory. Let’s change a timezone to Canada/Pacific. Back up the current locatime file:

# mv /etc/localtime /etc/localtime.bak

Create a symlink to the timezone you want to set:
# ln -s /usr/share/zoneinfo/Canada/Pacific /etc/localtime

Configure CentOS to Sync Time with NTP Time Servers

You can configure automatic time synchronization on your host with an external NTP (Network Time Protocol) server. To do it, you must install the ntp service. For example, you can install it using yum in CentOS 7:

# yum install ntp -y

After the installation, start the ntpd service and add it to startup:

# systemctl start ntpd.service
# systemctl enable ntpd.service

Make sure that the service is running:

# service ntpd status

Redirecting to /bin/systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-10-11 15:37:33 +06; 5min ago
Main PID: 3057 (ntpd)
CGroup: /system.slice/ntpd.service
└─3057 /usr/sbin/ntpd -u ntp:ntp -g

Specify the NTP servers to synchronize time with in /etc/ntp.conf:

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org

Time is synchronized in turn. If the first NTP server is not available, the second one is used, etc.

You can synchronize time with the specified NTP server manually using this command:

# ntpdate 192.168.1.23

By default, ntpd enables “11 minute mode”. It means that time will be synchronized every 11 minutes. If you cannot use the ntpd daemon, you can configure time synchronization using cron. Add the following command to cron:

# ntpdate pool.ntp.org

How to Sync Time in CentOS 8 using Chronyd?

In CentOS 8 you will have to use chrony to synchronize time, since ntp and ntpdate have been removed from the official repositories.

The main benefits of chrony are:

  • High speed and accuracy of time synchronization;
  • Proper operation if you don’t have access to master clock (ntpd requires regular requests);
  • By default, time is not modified right after the synchronization to prevent any problems for running programs;
  • Uses less resources.

By default, chrony is already installed in CentOS Linux, but if you don’t have it on some reason, install it:

# dnf install chrony

Like any other service, chrony needs to be started and added to startup after installation:

# systemctl start chronyd
# systemctl enable chronyd

Check the chronyd service status:

# systemctl status chronyd

systemctl status chronyd

To make sure that the time synchronization is working, run this command:

# timedatectl status

NTP Service: active

timedatectl status NTP Service: active

Chrony configuration file is /etc/chrony.conf. Specify the list of NTP servers you want to use for synchronization. Like ntp, chrony has a command-line interface: chronyc. To view the information about the current time synchronization options, run this command:

# chronyc tracking

To view the information about sync servers:

# chronyc sources

If you want to set the specific date and time manually, you can use date, but previously disable the chronyd daemon.

Common Time Syn Issues in CentOS

In this section, I will describe typical errors that appear when working with timedatectl, ntp.

During the manual time synchronization you may come across this error:

# ntpdate pool.ntp.org

ntpdate [26214]: the NTP socket is in use, exiting

This means that the ntpd daemon is running and is preventing manual time synchronization. To manually synchronize the time, stop the ntpd daemon:

# service ntpd stop

And run the synchronization again.

The same error may occur when working with timedatectl:

Failed to set time: Automatic time synchronization is enabled.

You must disable automatic sync in timedatectl:

# timedatectl set-ntp 0

And run this command to set the time and date you want:

# timedatectl set-time '2020-11-12 17:41:00'

When working with time zones, it may occur that they are not installed on your server and you are not able to create a symlink for localtime. To make time zones available on your host, install the tzdata tool:

# yum install tzdata -y

Also, you may face some errors during manual synchronization like the following one:

11 Oct 21:11:19 ntpdate[897482]: sendto(xx.xx.xx.98): Operation not permitted

In this case, check your firewalld/iptables rules and make sure that the UDP Port 123 is open on your server. Also, some NTP hosts may not be available during validation.

0 comment
1
Facebook Twitter Google + Pinterest
previous post
Managing System Reserved Partition in Windows 10
next post
How to Check or Update Java Version in Windows with PowerShell?

Related Reading

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Fixing ‘The Network Path Was Not Found’ 0x80070035...

August 30, 2023

How to Install and Configure Ansible on Linux

August 27, 2023

Computer Doesn’t Turn Off After Shutting Down Windows...

August 26, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Configure MariaDB Master-Master/Slave Replication?
  • How to Mount Google Drive or OneDrive in Linux?
  • KVM: How to Expand or Shrink a Virtual Machine Disk Size?
  • Adding VLAN Interface in CentOS/Fedora/RHEL
  • Install and Configure SNMP on RHEL/CentOS/Fedor
  • Configuring High Performance NGINX and PHP-FPM Web Server
  • Configuring Network Settings on RHEL/CentOS
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top