Determine the time difference between two linux servers

ntpdate -q does what you want.

Example:

root@host1:~# ntpdate -q host2 
server host2, stratum 4, offset 109.584520, delay 0.77560
17 Apr 21:48:16 ntpdate[28849]: no server suitable for synchronization found

In this case, the servers have a difference of about 110 seconds.


If the two servers are NTP peers, use

  ntpq -p

Which will show current offsets

Note that NTP takes into account network latency. If you know each server's offset from a common NTP server, that is about as accurate as you can get using standard tools.


UPDATE

I have two unix servers using NTP. Lets see what sort of time they are keeping:

$ sudo /usr/sbin/ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 hufu.ki.iif.hu  185.219.2.214    2 u   12   64    1   71.755   -0.073   0.001
 web.puflet.info 188.138.107.156  3 u   11   64    1   78.248    0.417   0.001
 84.2.44.19      10.20.75.140     2 u   10   64    1   74.721   -1.076   0.001

$ sudo /usr/sbin/ntpq -p otherbox
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp2.exa-networ 195.66.241.10    2 u  799 1024  377   43.405    7.796 218.471
+mantaray.netine 249.240.53.144   3 u  289 1024  377   34.782    8.484 212.631
*rilynn.me.uk    81.2.117.228     2 u  765 1024  377   45.665    6.804 142.023
+ntp.thirdlight. 193.67.79.202    2 u  791 1024  377   38.322    9.871 223.397

They are using different servers because they use servers from the ntp pool.

I'll temporarily add otherbox to this server's config so I can directly measure the time offset

$ sudo vi /etc/ntp.conf
 (added `server otherbox`)

$ sudo /sbin/service ntpd restart

$ sudo /usr/sbin/ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 gamma.h3x.no    78.70.33.22      3 u    4   64    1   34.840   -0.964   0.001
 web.puflet.info 188.138.107.156  3 u    3   64    1   78.148   -1.243   0.001
 alpha.rueckgr.a 129.69.1.153     2 u    2   64    1   61.495   -2.362   0.001
 otherbox.exampl 60.155.73.34     3 u    1   64    1    0.604  -11.286   0.001

It looks like timestamps on my two servers are about 11 ms different.


You can also do the following on host1:

root@host1# clockdiff -o host2

Tags:

Time

Ntp