ntpdate命令遇到“the NTP socket is in use, exiting”

电玩女神 2022-08-08 11:48 473阅读 0赞
  1. #ntpdate pool.ntp.org
  2. 15 May 10:51:02 ntpdate[50325]: the NTP socket is in use, exiting

这个提示表明NTP的端口已经被占用了,该端口默认为123,并且是UPD模式。可以使用nc或者netstat命令查看那个服务占用了此端口,例如:

  1. nc -uz -w 3 172.0.0.1 123
  2. netstat -nupl | grep "123"

一般情况下,别的服务是不会占用这个端口的,所以可能的结果是ntpd服务在占用。此时,可以使用ntpdate命令的-u参数解决此问题,即:

  1. # ntpdate -u pool.ntp.org
  2. 15 May 11:19:13 ntpdate[28173]: adjust time server 202.118.1.81 offset -0.029390 sec

同步成功。参数u说明如下:

Direct ntpdate to use an unprivileged port for outgoing packets. This is most useful when behind a firewall that blocks incoming traffic to privileged ports, and you want to synchronize with hosts beyond the firewall. Note that the -d option always uses unprivileged ports.

简单的说明就是:它不再使用默认的端口,而是使用了一个别的端口,所以避免了端口冲突。

顺便附上公网上有效的几个ntpd服务器:

ntp.fudan.edu.cn (复旦)

asia.pool.ntp.org(台警大授时中心-台湾)

time.windows.com (微软公司授时主机-美国)

time.nist.gov (美国)

pool.ntp.org

发表评论

表情:
评论列表 (有 0 条评论,473人围观)

还没有评论,来说两句吧...

相关阅读