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 0.centos.pool.ntp.org 1.centos.pool.ntp.org 2.centos.pool.ntp.org

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.

Two small things before you go

If something didn’t work on your setup, leave a comment and tell me which distro and version you’re on. I read every one, and most of these articles got better because a reader pointed out what was missing.

And if it did work, share it. TecMint has stayed free for 14 years because people pass these articles around, and that traffic is what pays for writing the next one.

Leave a comment
Get two free Linux courses

Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.

Pro TecMint
Get lifetime access for $99

If you want to go beyond the free tutorials, Pro gives you 18 courses, 5 ebooks, and every future course I add. One payment, lifetime access, no renewals.

Aaron Kili
Aaron Kili
Contributor
About the author

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.

4 Comments

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.

      Reply

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.