CentOS how to sync local Datetime with NTP time servers

Sync CentOS local DateTime with NTP time servers

Given install the ntpd and ntpdate clients on our Linux host.
(Same with Ubuntu and other Unix server)

$ yum install ntp ntpdate

If yum is not installed, just run the following command:

$ sudo apt install yum

Then start and enable the ntpd service.

$ systemctl start ntpd

$ systemctl enable ntpd

$ systemctl status ntpd

Then run the following command to configure the NTP Servers.

$ ntpdate -u -s 0.centos.pool.ntp.org 1.centos.pool.ntp.org 2.centos.pool.ntp.org

Above command telling the ntpdate to use an unprivileged port for outgoing packets with the -u switch and to write logging output to the system syslog facility using the -s switch.

Then restart the ntpd daemon.

# systemctl restart ntpd

Then check if NTP synchronization is enabled and running.

# timedatectl

And for the last step, set the hardware clock to the current system time using the -w switch.

# hwclock -w

Congratulations! You’ve now successfully set your NTP client on CentOS.