如何将 ntp 服务器的时间与我的服务器的时间进行比较?

Joh*_*hir 33 ntp time ntpd

我在一个盒子上运行 ntpd。我想看看盒子上的时间与从 ntp.ubuntu.com 检索到的时间相比如何。是否有捷径可寻?

use*_*517 36

您可以使用ntpdate查询时间服务器

ntpdate -q ntp.ubuntu.com


jsc*_*ott 20

ntpq -p ntp.ubuntu.com

来自man ntpq

...
-p     Print  a list of the peers known to the server as well as a summary of their state. This is equivalent to the peers interactive command.
...
Run Code Online (Sandbox Code Playgroud)

编辑:主机现在超时。 ntpq -p pool.ntp.org将返回一个有效的结果。

  • @mivk @Jonathon 实际上,`ntpq -p` 不是在要求时间,而是在要求对等节点和其他变量的列表。如果服务器有 `noquery` 限制,它将超时。 (10认同)
  • `ntpq -p pool.ntp.org` 在我的两台机器上超时,而 `ntpdate -q pool.ntp.org` 没有这样的问题。正如 GnP 所说,`ntpq -p` 不会做用户期望的事情。这个不正确的答案可能应该被删除。此外[`ntpq`不能在没有相关ntp守护进程的情况下安装在Debian下](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=422347)! (5认同)
  • ntpdate 已被弃用,因此最好养成使用 ntpq 的习惯。不过我自己还是一直用ntpdate,老习惯难改。 (2认同)
  • @mivk *“可能是因为 ISP 阻止了它”* 这毫无意义。都是相同的 NTP 协议。 (2认同)

小智 12

实际上,该命令ntpq -c "rv 0 clock" ntp.ubuntu.com将以标准格式返回服务器的时间:这是来自ca.pool.ntp.org的结果:

clock=d1b5aa9c.b8f9697a  Wed, Jun 29 2011  9:43:56.722
Run Code Online (Sandbox Code Playgroud)