[我的Linux技术支持生涯]运行ntpq -p出现“timed out, nothing received”错误

来源:互联网 发布:帝国cms 调用栏目内容 编辑:程序博客网 时间:2024/06/06 14:13

现象:在客户端和服务器端运行ntpq -p,均出现"timed out, nothing received",同时service ntpd status查看服务器和客户端的服务都是在正常运行。


排查:

1. 运行ntpq命令,进入交互模式,输入timeout 1000000,手动调整timeout时间,再输入peers查询,仍有 上述错误提示;

2. 查看了/etc/ntp.conf,没发现有可疑之处;

3. 在另外的两台机器中按照故障机器的/etc/ntp.conf配置ntp服务,运行ntpq -p能正确并很快得到信息;可见配置文件应该没错;

4. strace ntpq -p  查看输出的信息,发现:

    connect(3, {sa_family=AF_INET, sin_port=htons(123), sin_addr=inet_addr("10.44.101.2")}, 16) = 0

     而正常的机器中,这里的ip地址为127.0.0.1

5. 查看/etc/hosts文件,客户端和服务器端的该文件,都没有"127.0.0.1       localhost.localdomain   localhost"这行;

6. 在/etc/hosts添加了"127.0.0.1       localhost.localdomain   localhost"这行后,运行ntpq -p能正常得到信息了。


结论:

/etc/hosts:

# Do not remove the following line, or various programs
# that require network functionality will fail.

某些人就喜欢改。


PS:使用strace可以省好多功夫。

原创粉丝点击