Crmgo Blog

CentOS Configuring the NTPD Time Server

CentOS Configuring the NTPD Time Server

mv /etc/localtime /etc/localtime.bak ln -s /usr/share/zoneinfo/Europe/Kiev /etc/localtime Over time, clocks may drift forward or backward, so they need to be periodically synchronized with reference time sources. In CentOS, this is done using the ntpd daemon. If ntpd is not already installed on the system, install it: 1…

CentOS Configuring the NTPD Time Server

 

mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Europe/Kiev /etc/localtime

Over time, clocks may drift ahead or fall behind, so they need to be periodically synchronized with reference time sources. In CentOS, this is done using the ntpd daemon.

Install the ntpd daemon if it is not already present in the system:

1
# yum -y install ntp

Synchronize the time once:

1
# ntpdate pool.ntp.org

If you receive a message like the NTP socket is in use, exiting, it means the ntpd daemon is already running. In this case, stop it:

1
# systemctl stop ntpd

Configure the CMOS clock in the BIOS to use UTC time:

1
# hwclock --systohc --utc

This command sets the hardware clock time to match the system time. As you may recall, we synchronized the system time using the commands above.

Check the contents of the /etc/sysconfig/clock file to ensure the system sets the local time correctly after boot. For Kyiv, it should contain the following:

ZONE="Europe/Kiev"
UTC=true
ARC=false

Configure the ntpd daemon to start automatically when the operating system boots:

1
# systemctl enable ntpd

Start the time synchronization daemon:

1
# systemctl start ntpd

Check the system time using the command:

1
# date

It should match the actual value.

Let's check whether the system time is synchronized with reference time servers (NTP servers) and if everything is in order using the ntpq -p command:

1
2
3
4
5
6
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp1.hetzner.de 192.53.103.103   2 u   98 1024  377    3.850    2.293   1.203
*ntp2.hetzner.de 192.53.103.104   2 u  335 1024  377    0.641    3.480   1.202
+ntp3.hetzner.de 192.53.103.104   2 u  322 1024  377    0.736    4.117   1.211

The ntpd daemon enables the "11 minute mode" in the Linux kernel. In this mode, system and hardware clocks are synchronized every 11 minutes. By default, this mode is disabled and is enabled only when a service requests it. The ntpd daemon is responsible for enabling this mode. Therefore, there is no need to additionally synchronize the hardware clock based on the system time.

P.S. Now the system and hardware clocks of your server will automatically synchronize with reference servers and always display the correct time.

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.