Greetings to fellow admins. Over the years, I have come across many questions about how to properly configure our Linux hosts to synchronize time with our corporate NTP servers.
So, I thought, why not create an article that describes in its simplest form the correct way to configure an NTP client to synchronize with NTP servers.
So let’s get started!
CentOS synchronization with NTP time servers
First of all, we need to install the ntpd and ntpdate clients on our Linux host. I am using CentOS but same on Ubuntu etc.
# yum install ntp ntpdate
If yum is not installed, just run the following command: sudo apt install yum. After installing it, we need to start and enable the ntpd service.
# systemctl start ntpd # systemctl enable ntpd # systemctl status ntpd
Now that this has been fixed, let’s 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
We tell ntpdate to use an unprivileged port for outgoing packets using the -u switch, and write the log output to the syslog tool using the -s switch.
Then let’s restart the ntpd daemon.
# systemctl restart ntpd
Now let’s check if NTP sync is enabled and working.
# timedatectl
And as a last hurray, we’ll set the hardware clock to the current system time with the -w switch.
# hwclock -w
Congratulations! You have successfully configured your NTP client on CentOS.
Hope you enjoyed the article!