ntpd在默认情况下监听大量的接口,我只希望监听127.0.0.1:123,因为我只希望本地主机同步时间。
如何做到这一点,我试图在Debian Wheezy上编辑/ etc / default / ntp:
NTPD_OPTS='-4 -I 127.0.0.1'
但是它仍然在全局监听0.0.0.0:123
有任何想法吗?
从/etc/default/ntp
删除所有-I
或--interface
选项,并将以下内容插入到/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
关于-i
选项的ntpd(1)
手册页摘录如下:
这个选项也意味着不打开除通配符和本地主机之外的其他地址。 请考虑使用更通用的configuration文件接口命令。
另请参阅ntp.conf(5)
的Debian手册页(在Arch Linux中找不到它ntp.conf(5)
。
使用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地址才能工作。
完整的/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
如果出于安全原因想要减less监听服务的数量,可以考虑使用openntpd,因为它不需要监听服务器作为客户端。 它被认为比ntpd稍微不准确; 在几百毫秒内是可靠的,但是这适用于大多数目的。