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

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.

Spread the love

Posted by News Monkey