How To Install And Configure NTP On CentOS 7

NTP stands for Network Time Protocol, an Internet standard protocol originally developed by Professor David L. Mills at the University of Delaware and it is used to synchronize the clocks of computers for some time reference. NTP uses UDP port 123 and uses a hierarchical, semi-layered system of time sources. Each level of this hierarchy is termed a stratum and is assigned a number starting with zero for the reference clock at the top. A server synchronized to a stratum n server runs at stratum n + 1. The number represents the distance from the reference clock and is used to prevent cyclical dependencies in the hierarchy. Please see picture below:
There are 4 lines in the picture above where the top line is stratum 0 and the bottom line is stratum 3. Yellow arrows show a direct connection and red arrows show a network connection. Stratum 0 devices are also known as reference clocks using high-precision timekeeping devices such as atomic clocks, GPS or other radio clocks. This article will explain how to install and configure NTP using CentOS 7. Make sure firewall and SELinux disabled first before we install NTP packages.

Install NTP package on the server using commands:

and then check the local time on our server using the command:

Adjust localtime file if we are in a different place with localtime file. If we stay in Jakarta, please change it with the command:

After that, type the command:

Here, the -u switch tells ntpdate to use an unprivileged port for outgoing packets and -s enables for logging output from the standard output (default) to the system syslog facility. Please see picture below:
install ntpRestart ntpd to synchronize CentOS NTP server date and time with your local date and time, check using the timedatectl command if NTP synchronization is enabled and if it is actually synchronized and using hwclock utility to set the hardware clock to the current system time using the -w flag:

If we want to display the status of NTP server, use the command:


Now, we want to configure client NTP on CentOS 7 with NTP server in 192.168.56.102. Before that, it is not recommended to use only two NTP servers and if more than one NTP server is required, four NTP servers are the recommended minimum because four servers protect against one incorrect timesource, or “falseticker”. If we use the firewall, we must open NTP port (UDP port 123):

Install NTP packages on the client using the command:

Then, go to /etc/ntp.conf file to configure NTP. Comment the default list of Public Servers from pool.ntp.org project and replace it with the list provided for your country like in the screenshot below:

The true option indicates if we have more than one NTP server then the client will synchronize the time with the server given the true option in the /etc/ntp.conf file. Then we must change localtime in the client. Adjust localtime file if we are in a different place with localtime file. If we stay in Jakarta, please change it with the command:

After that, restart ntp using these commands:

If we want to display the status of NTP client, use the command:

References:
ntp.org
en.wikipedia.org
tecmint.com
thegeekstuff.com
access.redhat.com

Leave a Reply

Your email address will not be published. Required fields are marked *