Bootstrap FreeKB - Linux Commands - ntpdate (synchronize to an NTP server)
Linux Commands - ntpdate (synchronize to an NTP server)

Updated:   |  Linux Commands articles

The ntpdate command can be used if the NTP server is NTPd. The ntpdate will produce no server suitable for synchronization found if the NTP server is not NTPd. For example, if the NTP server is Chrony, the ntpdate command will produce errors.

Use apt-get or yum to install the ntpdate utility.

[root@server1 ~]# yum install ntpdate

 

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to enable ntpdate.

systemctl enable ntpdate

 

If your system is using init, use the chkconfig command to enable ntpdate.

chkconfig ntpdate on

 

The ntpdate command without any options can be used to determine if the client machine is synchronized with an NTPd server. In this example, the client machine is not synchronized with an NTPd server.

[root@client1 ~]# ntpdate
19 Apr 17:06:46 ntpdate[7219]: no servers can be used, exiting

 


Test the connection to an NTPd server

The  -q (query) option can be used to verify that you are able to connect to a NTPd server. In this example, the client is able to connect to ntp1.example.com.

[root@client1 ~]# ntpdate -q ntp1.example.com
server 192.168.0.119, stratum 3, offset -0.000526, delay 0.02586
8 Nov 09:24:01 ntpdate[25468]: adjust time server 192.168.0.119 offset -0.000526 sec

 


Synchronize to an NTP server

The ntpdate command followed by the hostname or IP address of an NTPd server can be used to configure a client to use the target NTPd server. In this example, the client will use ntp1.example.com as the NTPd server.

[root@client1 ~]# ntpdate ntp1.example.com
8 Nov 09:24:01 ntpdate[25468]: adjust time server 192.168.0.119 offset -0.000526 sec

 

The ntpstat command without any options confirms that client is synchronized with the NTPd server.

[root@server1 ~]# ntpstat
synchronised to NTP server (192.168.0.9) at stratum 3 
   time correct to within 17 ms
   polling server every 1024 s

 

The date command produces the time according to the NTPd server.

[root@server1 ~]# date
Tue Nov 8 09:30:02 CST 2016

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 8c383e in the box below so that we can be sure you are a human.