NTP本地查询总是超时

我有一个CentOS 6.4服务器,它没有任何iptable规则,它使用以下configuration作为服务运行NTP守护进程:

driftfile /var/lib/ntp/drift server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org server 3.pool.ntp.org restrict default ignore restrict 127.0.0.1 

当我运行ntpq来查询对等体时,会收到以下响应:

 ntpq> peers localhost.localdomain: timed out, nothing received 

dig表明:

 localhost.localdomain. 86400 IN A 127.0.0.1 

为什么不ntp查询工作?

在RHEL / CentOS 6和7上,无论出于何种原因, ntpq尝试在:: 1而不是127.0.0.1处的IPv4环ntpq查询IPv6环回。 考虑到这一点,我将这一行添加到我的/etc/ntp.conf文件中:

 restrict ::1 

保存文件,然后重新启动ntpd

 service ntpd restart 

现在命令:

 ntpq -p 

按预期工作。 (这与在命令行模式下运行ntpq然后发出peers命令相同。)

我更喜欢这个解决scheme,因为你不必通过一个潜在的公共以太网接口与ntpd进行通信,这可能是一个安全问题。

我期待ntpq通过127.0.0.1查询本地服务器,但事实certificate是通过以太网接口查询本地服务器。

虽然我不知道为什么本地ntp查询将不得不通过以太网,但在我添加的configuration文件

 restrict <eht0 ip address> 

现在NTP工作正常。

当读第二个答案时,我意识到这个问题的原因可能在/ etc / hosts上。 然后在/ etc / hosts上添加localhost,然后重试。

 127.0.0.1 localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 

之前:

 ems@rack6-storage-2:~$ sudo service ntp stop ; sudo ntpdate 0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org ; sudo service ntp start ; PATH=/usr/bin:/usr/sbin ntpdc -p * Stopping NTP server ntpd ...done. 18 Dec 08:18:31 ntpdate[35729]: adjust time server 202.156.0.34 offset -0.000467 sec * Starting NTP server ntpd ...done. localhost.sdcorp.global.sandisk.com: timed out, nothing received ***Request timed out 

后:

 ems@rack6-storage-2:~$ sudo vim /etc/hosts ems@rack6-storage-2:~$ sudo service ntp stop ; sudo ntpdate 0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org ; sudo service ntp start ; PATH=/usr/bin:/usr/sbin ntpdc -p * Stopping NTP server ntpd ...done. 18 Dec 08:27:09 ntpdate[36056]: adjust time server 202.156.0.34 offset 0.015872 sec * Starting NTP server ntpd ...done. remote local st poll reach delay offset disp ======================================================================= =golem.canonical 10.242.43.103 16 64 0 0.00000 0.000000 4.00000 =frontier.innola 10.242.43.103 16 64 0 0.00000 0.000000 4.00000 =sg01.7asecond.c 10.242.43.103 16 64 0 0.00000 0.000000 4.00000 =time2.maxonline 10.242.43.103 16 64 0 0.00000 0.000000 4.00000 =pontoon.latt.ne 10.242.43.103 16 64 0 0.00000 0.000000 4.00000 

在提示“重新安装”之前,人们应该仔细阅读给定的configuration。 这个错误是非常明显的。

从我看到的,你已经configuration了一个NTP 服务器,但你指向一个POOL

服务器0.pool.ntp.org

尝试

游泳池0.pool.ntp.org

而是使用专用服务器而不是池来使用“服务器”。