如何防止 ntpd 监听 0.0.0.0:123?

Joh*_*mBF 30 linux debian ntpd

ntpd 默认监听多个接口,我只希望它监听 127.0.0.1:123,因为我只希望本地主机同步时间。

如何做到这一点,我尝试在 Debian Wheezy 上编辑 /etc/default/ntp:

NTPD_OPTS='-4 -I 127.0.0.1'

但它仍然在 0.0.0.0:123 上全局侦听

有任何想法吗?

Lek*_*eyn 36

删除所有-I--interface选项/etc/default/ntp并将以下内容插入到您的/etc/ntp.conf:

interface ignore wildcard
interface listen 127.0.0.1
interface listen ::1
# NOTE: if you want to update your time using remote machines,
# add at least one remote interface address:
#interface listen 2001:db8::1
#interface listen 192.0.2.1
Run Code Online (Sandbox Code Playgroud)

ntpd(1)关于该-i选项的手册页摘录:

此选项还意味着不打开其他地址,通配符和本地主机除外。请考虑使用配置文件接口命令,它更通用。

另请参阅 Debian 手册页(我在 Arch Linux one 中找不到它)ntp.conf(5)

  • ntp 需要绑定在可路由的接口上才能与时间服务器同步。请参阅下面的 meepmeep 的回答。 (6认同)

小智 18

由于 ntp 仅在 127.0.0.1 上侦听,因此它似乎无法启动与公共 ntp 服务器的连接:

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
ks370079.kimsuf **.INIT.**       16 -    -   64    0    0.000    0.000   0.000
Run Code Online (Sandbox Code Playgroud)

它必须绑定到可路由的 IP 地址才能工作。


小智 7

完整的 /etc/ntp.conf 协议中立(IPv4 &| IPv6)

driftfile /var/lib/ntp/ntp.drift

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

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

restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

restrict lo

interface ignore wildcard
interface listen lo
Run Code Online (Sandbox Code Playgroud)


cop*_*cat 7

如果出于安全原因要减少侦听服务的数量,可以考虑使用 openntpd,因为它不需要侦听服务器充当客户端。它被认为比 ntpd 的准确度稍低;它在几百毫秒内是可靠的,但这适用于大多数目的。