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.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
    • @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...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.