The ntp protocol is used to configure and update date and time information for IT systems. The ntpdate command is a tool used to configure and update the date and time information with the ntp protocol. The ntpdate simply queries the date and time information and sets the current system date and time according to the configured timezone information. The ntpdate command works and communicates over the network and if the network is working properly and reliably the date and time configuration will be accurate.
Install ntpdate
The ntpdate command is not installed by defualt by most of the Linux distributions. But it can be installed like below.
Install ntpdate For Debian, Ubuntu, Mint:
sudo apt install ntpdate
Install ntpdate For Fedora, CentOS, RHEL:
sudo yum install ntpdate
Update Date and Time with ntpdate
The ntpdate command run the NTP protocol and connect to the specified NTP server to update date and time. Time settings are important and requires root privielges. So sudo command is used before the ntpcommand. Also we will specify the ntp server IP address or hostname.
sudo ntpdate ntp.ubuntu.com
The output is like below. The updated date and time information is provided. Also the adjusted time time server IP address is listed.
20 Mar 13:06:33 ntpdate[30504]: adjust time server 91.189.89.198 offset -0.000801 sec
Query Date and Time with ntpdate (Do Not Update)
By default the ntpdate command updates the current system date and time. But we can also run ntpdate command to only list current date and time bu not update. The -q option can be used to only query not update.
sudo ntpdate -q ntp.ubuntu.com
server 91.189.91.157, stratum 2, offset 0.002672, delay 0.15669 server 91.189.89.199, stratum 2, offset 0.001812, delay 0.08936 server 91.189.94.4, stratum 2, offset -0.022692, delay 0.14595 server 91.189.89.198, stratum 2, offset 0.004641, delay 0.09351 20 Mar 13:20:48 ntpdate[30619]: adjust time server 91.189.89.199 offset 0.001812 sec
Set Timeout For ntpdate
When the ntpdate command try to connect remote NTP server it has default timeout value which is 1 second. If the network has latency or NTP server related problems like load the timeout for the ntpdate command can be explicitly set a higher value. The ntpdate timeout value can be set with the -t option.
sudo ntpdate -t 3 ntp.ubuntu.com