跳转至

ntpdate 命令


2014-04-16 by dongnan

举个栗子

默认超时时间

time /usr/sbin/ntpdate 172.27.233.1
15 Apr 14:50:25 ntpdate[8879]: no server suitable for synchronization found

real    0m4.102s    # 这里
user    0m0.000s
sys    0m0.001s

指定超时时间

time /usr/sbin/ntpdate -t 0.2 172.27.233.1
15 Apr 14:50:09 ntpdate[8853]: no server suitable for synchronization found

real    0m0.902s    # 这里
user    0m0.000s
sys    0m0.001s

只查询不做时间同步

/usr/sbin/ntpdate -q 172.27.233.45

server 172.27.233.45, stratum 3, offset 0.002026, delay 0.02579
15 Apr 15:59:41 ntpdate[7203]: adjust time server 172.27.233.45 offset 0.002026 sec

PS:这个参数可以用于测试ntp服务是否可用,比如 keepalivedhealtchecker等。

Debug模式(测试ntp 时间服务)

ntpdate -d 172.16.1.201
28 Dec 14:38:21 ntpdate[4426]: ntpdate 4.2.6p5@1.2349-o Tue May 31 10:28:55 UTC 2016 (1)
Looking for host 172.16.1.201 and service ntp
host found : localhost
transmit(172.16.1.201)
receive(172.16.1.201)
transmit(172.16.1.201)
receive(172.16.1.201)
transmit(172.16.1.201)
receive(172.16.1.201)
transmit(172.16.1.201)
receive(172.16.1.201)
172.16.1.201: Server dropped: strata too high
server 172.16.1.201, port 123
stratum 16, precision -21, leap 11, trust 000
refid [172.16.1.201], delay 0.02620, dispersion 0.00005
transmitted 4, in filter 4
reference time:    00000000.00000000  Mon, Jan  1 1900  7:36:42.000
originate timestamp: dc0ddd58.2751fc27  Wed, Dec 28 2016 14:42:32.153
transmit timestamp:  dc0ddc63.23b769e4  Wed, Dec 28 2016 14:38:27.139
filter delay:  0.02744  0.02620  0.02631  0.02640
         0.00000  0.00000  0.00000  0.00000
filter offset: 245.0132 245.0134 245.0134 245.0135
         0.000000 0.000000 0.000000 0.000000
delay 0.02620, dispersion 0.00005
offset 245.013416

28 Dec 14:38:27 ntpdate[4426]: no server suitable for synchronization found

命令帮助

NAME
       ntpdate - set the date and time via NTP

       Disclaimer: The functionality of this program is now available in the ntpd program. See the -q command 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 [ ... ]

-t timeout
Specify  the  maximum time waiting for a server response as the value timeout, 
in seconds and fraction. The value is is rounded to a multiple of 0.2 seconds. 
The default is 1 second, a value suitable for polling across a LAN.

-q  Query only - don't set the clock.

-d  Enable the debugging mode, in which ntpdate will go through all the steps, but not adjust the local clock.  
Information  useful  for  general debugging will also be printed.

欢迎关注微信公众号: 运维录

Back to top