Linux/CentOS: How To Set Date/Time Synchronization With Time Server
In the Linux system, how can we let the system time consistent with the server time ? How to synchronize the time of CentOS system ? How to make the system time and the time server time for automatic synchronization? This post will introduce you how to set the CentOS date and time synchronization with the server:
We can use the rdate and ntpdate two commands to perform time synchronization.
you need to check if those two tools have been installed using rpm -qa command, or using the following command to install it.
$yum install rdate
Or
$yum install ntpdate
CentOS Using rdate To Synchronize Time
The rdate command is mainly used to get time from remote time server , if you want to update to the system, you need to use the “-s” option.
rdate command synopsis:
Rdate – get the time via the network
Rdate [-p] [-s] [-u] [-l] [-t sec] [host...]
DESCRIPTION
Rdate connects to an RFC 868 time server over a TCP/IP network, printing the returned time And/or setting the system clock.
OPTIONS
-p Print the time returned by the remote machine. -s Set the system time to the returned time. -u Use UDP instead of TCP as the transport. -l Use syslog to output errors (cron.warning) and output (cron.info). -t Set timeout in seconds for every attempt to retreive date.
Example:
synchronous time from the network time server time.nist.gov and set that time to current system, issue the following command:
$rdate -s time.nist.gov
CentOS use the ntpdate tool to synchronize time
The ntpdate tool will automatically from the specified time server for time synchronization.
Ntpdate command synopsis:
Ntpdate – set the date and time via NTP
Disclaimer: The functionality of this program is now available in the ntpd program. See the -q com-
Mand line option in the ntpd – Network Time Protocol (NTP) daemon page. After a suitable period of
Mourning, the ntpdate program is to be retired from this distribution
SYNOPSIS
Ntpdate [-46bBdqsuv] [-a key] [-e authdelay] [-k keyfile] [-o version] [-p samples] [-t
Timeout] [-U user_name] server […]
Example:
Using ntpdate command to synchronize from the network time server, issue the following command:
$ntpdate time.nist.gov
Of course you also can set up a NTP server for other hosts synchronization.
How to set the automatic synchronization in linux system
The above two command will only make once synchronization , so how to let the system automatically synchronize the time at a specific time, you can confiure the /etc/crontab configuration file, add the following message into:
0001 * * root rdate -s time.nist.gov
done…