How to Obtain Accurate Server Time in CentOS

In this article, we will show you how to quickly get accurate server time in CentOS distribution. Normally, if you have installed CentOS with a desktop environment, the easiest way to configure your computer to synchronize its clock with a remote server via the GUI “Enable Network Time Protocol” feature.

However, some times the above feature fails to work as expected. In this article, we will show you a straightforward way to set a accurate server time via the command line.

Read Also: Setting Up “NTP (Network Time Protocol) Server” in RHEL/CentOS 7

Note: All commands in this article are run as root user, if you are administering the system as a normal user, employ the sudo command to gain root privileges.

We can do this using the ntp and ntpdate command line utility, which sets system date and time via NTP. If you do not have this package installed on your system, run the command below to install it:

# yum install ntp ntpdate

Once you have installed the packages, start and enable the ntpd service, and view its status as follows.

# systemctl start ntpd
# systemctl enable ntpd
# systemctl status ntpd
Start NTP Service
Start NTP Service

Then run the ntpdate command below to add the specified CentOS NTP servers. 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.

# ntpdate -u -s

Next, restart the ntpd daemon to synchronize CentOS NTP server date and time with your local date and time.

# systemctl restart ntpd

Now check using the timedatectl command if NTP synchronization is enabled and if it is actually synchronized.

# timedatectl

Lastly, using the hwclock utility, set the hardware clock to the current system time using the -w flag as follows.

# hwclock  -w 

For more information, see the ntpdate and hwclock man pages.

# man ntpdate
# man hwclock

You might also like to read these following related articles.

  1. How to Synchronize Time with NTP Server in Ubuntu
  2. How to Check Timezone in Linux
  3. 5 Useful Commands to Manage File Types and System Time in Linux
  4. How to Set Time, Timezone and Synchronize System Clock Using timedatectl Command

That’s it! You can ask any questions or share your thoughts via the comment section below.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

4 thoughts on “How to Obtain Accurate Server Time in CentOS”

    • @borys

      Unfortunately, chrony it not preinstalled. You must install and configure it before using it just like ntp. Therefore you can choose which time sync daemon to use, which is more or less the same.

      Thanks for the useful information.


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.