ntpdate:找不到适合同步的服务器

我的时钟已关闭 ,所以我想使用ntpdate进行同步。 我尝试了几种不同的NTP服务器,但由于某种原因,我总是收到以下错误消息:

 $ sudo ntpdate ntp.ubuntu.com 4 Mar 12:27:35 ntpdate[1258]: no server suitable for synchronization found $ sudo ntpdate pool.ntp.org 4 Mar 12:27:50 ntpdate[1267]: no server suitable for synchronization found $ sudo ntpdate de.pool.ntp.org 4 Mar 12:28:01 ntpdate[1273]: no server suitable for synchronization found $ sudo ntpdate us.pool.ntp.org 4 Mar 12:28:12 ntpdate[1276]: no server suitable for synchronization found 

相关问题

我查看过相关问题 ,但没有解决我的问题:

  • 无法使用NTP同步时间 – 这个人得到的错误与我不同; 他的问题是与ntpd守护进程发生冲突。 我根本没有安装ntp软件包(包括ntpd守护程序)。
  • 如何使用ntp强制更新时钟? – 这个人的问题是,当他将ntpdate命令放入他的/etc/rc.localntpdate命令在启动时不能正常工作,而且问题同样与正在运行的ntpd守护进程发生冲突。 我也没有尝试在启动时运行ntpdate ,也没有(再次)安装ntpd守护进程。
  • 无法使用`ntpdate`同步时间,错误:“没有适合发现同步的服务器” – 这是我的错误,但接受的答案基本上是“使用ntpd而不是ntpdate ”。 Aaarggh …

我尝试过的事情

我安装了ntp包

…并尝试使用ntpd守护程序而不是ntpdate实用程序。 它也不会同步我的时间; 守护进程很好,但我的时钟仍然关闭。 我甚至尝试使用后/etc/ntp.conf中接受的答案中的确切/etc/ntp.conf ,然后重新启动守护进程。 不行。 无论如何,我不想使用守护进程。 我完全知道ntpdate被认为是“已弃用”,建议使用ntpd -q代替。 另见:

  • ntpd vs ntpdate:优点和缺点

但由于ntpd对我来说也不起作用, 问题出在其他地方 。 而且我发现我不想为了同步时钟而安装任何额外的软件包。 ntpdate预先安装了Ubuntu, 它应该可以正常工作 。 所以我再次卸载了ntp包。

也许端口123被阻止?

从这篇文章:

  • 尝试运行`ntpdate`时,“找不到适合同步的服务器”错误

…我明白端口123可能会在我的工作地点被我的计算机/网络阻止。 确实,

 $ sudo nmap -p123 -sU -P0 localhost ... PORT STATE SERVICE 123/udp closed ntp ... $ sudo ufw allow 123/udp Rules updated Rules updated (v6) $ sudo nmap -p123 -sU -P0 localhost ... PORT STATE SERVICE 123/udp open ntp ... 

但仍然:

 $ sudo ntpdate ntp.ubuntu.com 4 Mar 13:06:16 ntpdate[4361]: no server suitable for synchronization found 

即使使用-u选项,它告诉ntpdate使用非特权端口进行同步(而不是端口123 ),这肯定不会阻止我的工作地点:

 $ sudo ntpdate -u ntp.ubuntu.com 4 Mar 13:06:28 ntpdate[4427]: no server suitable for synchronization found 

地层可能太高了?

最后,从serverfault的这篇文章:

  • ntpdate -d Server掉线Strata太高了

……我想也许NTP服务器的层次太高了。 但他们不是。 让我们看一点调试信息:

 $ sudo ntpdate -dv ntp.ubuntu.com 4 Mar 13:12:24 ntpdate[4523]: ntpdate 4.2.6p5@1.2349-o Wed Oct 9 19:08:07 UTC 2013 (1) Looking for host ntp.ubuntu.com and service ntp host found : golem.canonical.com transmit(91.189.89.199) transmit(91.189.94.4) transmit(91.189.89.199) transmit(91.189.94.4) transmit(91.189.89.199) transmit(91.189.94.4) transmit(91.189.89.199) transmit(91.189.94.4) transmit(91.189.89.199) transmit(91.189.94.4) 91.189.89.199: Server dropped: no data 91.189.94.4: Server dropped: no data server 91.189.89.199, port 123 stratum 0, precision 0, leap 00, trust 000 refid [91.189.89.199], delay 0.00000, dispersion 64.00000 transmitted 4, in filter 4 reference time: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000 originate timestamp: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000 transmit timestamp: d6c041ae.e6166441 Tue, Mar 4 2014 13:12:30.898 filter delay: 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 filter offset: 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 delay 0.00000, dispersion 64.00000 offset 0.000000 server 91.189.94.4, port 123 stratum 0, precision 0, leap 00, trust 000 refid [91.189.94.4], delay 0.00000, dispersion 64.00000 transmitted 4, in filter 4 reference time: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000 originate timestamp: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000 transmit timestamp: d6c041af.1948fc50 Tue, Mar 4 2014 13:12:31.098 filter delay: 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 filter offset: 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 delay 0.00000, dispersion 64.00000 offset 0.000000 4 Mar 13:12:33 ntpdate[4523]: no server suitable for synchronization found 

Pfeeewww …这是一个很长的,对不起。 我很难过。 有什么线索吗?

更新:其他信息

无论NTP服务器HOSTNAME是否在/etc/ntp.conf都有数字,并且无论ntpd服务是否正在运行,每当我运行sudo ntpdate -u HOSTNAME ,我都no server suitable for synchronization found 。 当ntpd服务没有运行时我也省略-u选项。 当ntpd服务正在运行并且我省略了-u选项时,我改为the NTP socket is in use, exiting

也:

 $ timedatectl status Local time: Wed 2014-03-05 13:11:54 CET Universal time: Wed 2014-03-05 12:11:54 UTC Timezone: Europe/Berlin (CET, +0100) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: no Last DST change: DST ended at Sun 2013-10-27 02:59:59 CEST Sun 2013-10-27 02:00:00 CET Next DST change: DST begins (the clock jumps one hour forward) at Sun 2014-03-30 01:59:59 CET Sun 2014-03-30 03:00:00 CEST 

但是这里的UTC时间不正确。 现在UTC时间是11:11 ,而不是12:11

和:

 $ sudo hwclock --show Wed 05 Mar 2014 01:11:56 PM CET -0.625627 seconds 

您的托管服务提供商阻止了ntp数据包。 一些ISP响应DDoS攻击已经实施了这种严厉的方法。 您可以看到ntpdate正在从ntpdate -vd发送数据包:

 transmit(91.189.94.4) transmit(91.189.89.199) transmit(91.189.94.4) transmit(91.189.89.199) 

我会联系你的ISP并询问他们是否阻止外部ntp请求,以及他们是否有可用于时间同步的本地服务器。

还有一些更加模糊的可能性,但由于您没有从syslog发布任何日志,因此很难排除它们。

这不是一个ntp答案,但是……

 sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" 

这和这里的curl版本。

我有同样的问题,这就是我解决它的方式。 我从上到下给出了详细的答案。 您可能希望跳到我的答案中间,或者只是参考下面的屏幕截图,以便一目了然地理解它。

首先安装ntpdate(显然你已经这样做了)

 sudo apt-get install ntpdate 

NEXT您需要使用服务器配置ntp,如下所示:

您至少应该在/etc/ntp.conf配置文件中设置以下参数: server

例如,使用nano文本编辑器打开/etc/ntp.conf文件:

 sudo nano /etc/ntp.conf 

找到服务器参数,如果为空,请按如下所示进行设置:

 server pool.ntp.org 

但通常在ubuntu中已经预先写了一些服务器

 server 0.ubuntu.pool.ntp.org server 1.ubuntu.pool.ntp.org server 2.ubuntu.pool.ntp.org server 3.ubuntu.pool.ntp.org 

在此处输入图像描述

然后保存文件并重新启动ntpd服务

 sudo /etc/init.d/ntpd start 

您可以使用以下命令立即将系统时钟同步到NTP服务器:

 sudo ntpdate pool.ntp.org 

或者只是运行已定义的服务器

 sudo ntpdate 0.ubuntu.pool.ntp.org 

或使用服务器定义的其他服务器

通常

 sudo ntpdate  

在此之后,您可能会使用Error NTP socket in use如下所示:

在此处输入图像描述

在那种情况下,只需运行

 ntpdate -u pool.ntp.org 

在ntp deamon运行时更新

或者只是停止deamon,更新并再次启动它,如下所示:

 sudo ntpdate pool.ntp.org sudo service ntp stop sudo ntpdate pool.ntp.org sudo service ntp start 

你会得到的

在此处输入图像描述

使用htpdate

如果网络中阻止了ntp传输,请安装htpdate。 它通过http协议同步时间。 根据手册页,准确度将持续0.5秒。

 sudo apt-get install htpdate sudo htpdate -a google.com 

安装程序包时将启动htpdate服务。 如果有互联网连接,时间将立即更新。

类似于亚历克斯的答案,这对我来说是绕过ntp端口被防火墙:

 sudo date -s "$(curl http://s3.amazonaws.com -v 2>&1 | \ grep "Date: " | awk '{ print $3 " " $5 " " $4 " " $7 " " $6 " GMT"}')" 

即使我们面临这个问题……但我们设法通过点击此命令来解决它:

 ssh localhost "sudo apt-get install ntp ntpdate ; sudo service ntp stop; sudo ntpdate 0.ubuntu.pool.ntp.org; sudo service ntp start" 

为此,您需要安装openssh-server

另外,在触发上面的ssh命令之前删除ntp和ntpdate( sudo apt-get remove --purge ntp ntpdate )。

只是一个建议。 我有这个问题已经有一段时间了,然后它开始工作了,但我发现磁盘上没有更多的空间了。