如何阻止 ntpd 监听 0.0.0.0:123?

如何阻止 ntpd 监听 0.0.0.0:123?

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

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

NTPD_OPTS='-4 -I 127.0.0.1'

但它仍然在 0.0.0.0:123 上进行全局监听

有任何想法吗?

答案1

从中删除所有-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

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

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

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

答案2

由于 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

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

答案3

完整的 /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

答案4

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

相关内容