Open In App

NTP Configuration in CentOS

Last Updated : 04 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

NTP(Network Transfer Protocol) is a protocol that is used for the synchronization of time over a network. It provides the service of setting the current time on the client’s request so that the client can set his clock on his system. There are three tiers of NTP servers:

  • Tier 1: Connected to atomic clocks.
  • Tier 2 and Tier 3: Carry the load of handling the requests all over the Internet.

The actual working of these servers is a lot more complex because of various factors such as communication delays, adjusting time, and keeping it in sync. But all that is hidden from the end users and the entire system is kept abstract. This protocol runs over port 123 UDP at the transport layer and chooses the nearest geographical location from the client’s server for syncing time. In this article, we will see the configuration of NTP on CentOS.

Steps for NTP configuration in CentOS

Step 1: Update the System

Updating the system and having the latest version of all the packages is an important part as we might get stuck in the later part of the installation. Use the yum package manager to update the system.

yum update -y

 

Step 2: Install the NTP package

After updating the system, install the NTP package by using the below command:

yum install ntp -y

 

Step 3: Configuring the NTP server

The information about the NTP configuration file resides in the /etc PATH. To add this information to the ntp.conf file we have to edit this file in the editor. We have to add the NTP server name and the IP address. Open the file using the below command. To get the servers of our region and timezone visit this site: https://www.pool.ntp.org/en/ 

Select your region and comment down the servers that are already in the file, and add down your servers.

vi  /etc/ntp.conf

 

This is how the .conf file looks.

 

 

The highlighted portion in red signifies the available servers that will be used for syncing purposes. Save the file with :wq, and exit. 

Step 4: Restarting the ntpd service

Now that we have made the relevant changes we have to restart the ntpd service to make these changes effective. Use the below command:

systemctl restart ntpd

 

Step 5: Check the Sync status of NTP

In this step we will check the status of synchronization of the NTP server, by using the below command:

ntpq -np

 

Meaning of the -n and -p flags:

  • -n: This is used for displaying the output of all the host addresses in a dotted-quad format.
  • -p: This is used to display the peers which are identified by the server.

Step 6: Final verification of time and date

After completing all the above steps, we should get the correct date and time according to our zone. We can confirm that by using the below command:

timedatectl 

 

The date command can also be used to verify the date and time.

 

Step 7: Querying about the delay and offset 

If we want to get info about offsets, and delays from the NTP server then we can do that by using the below command. 

ntpdate -q pool.ntp.org

 

So this is how you can configure the NTP protocol on your CentOS distribution. This comes in pretty handy because the internal clocks in the systems can sometimes cause issues that may result in inconsistent time problems. Hope you liked the article.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads