我试图让一个没有外部互联网访问的系统(A)从局域网上另一个可以访问互联网的系统获取时间(B)。
在A的ntp.conf(整个内容在底部)中,我添加了:
server 192.168.2.102
restrict 192.168.2.102
参考B的IP。经过一个小时的阅读手册页、查看在线示例等之后,据我所知,这应该意味着它将使用该本地服务器,并信任它做任何事情。
然而,这不起作用。我可以在 中观看两个交换时间wireshark
,并ntpq -p
在 A 上运行显示:
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.2.102 .INIT. 16 u 16 64 0 0.000 0.000 0.000
如果我ntpd
在 A 上停止并尝试ntpd -gq
,我可以再次在wireshark中来回观看,但一两分钟后命令超时并显示“未找到服务器”。
我什至尝试添加到 A 的配置中:
fudge 192.168.2.102 stratum 1
没有任何区别。
如何强制 ntpd 设置特定服务器的时间? 看起来这曾经很容易使用ntpdate
——它已被贬值并且在系统上不存在。
这是机器 A 的整个 ntp.conf。这是 Debian 的老版本。我所做的唯一更改是添加涉及 192.168.2.102 的行,并注释掉 debian 池服务器以尝试消除那里的混乱,因此无论如何它们都是无法访问的。
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
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
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
server 192.168.2.102
restrict 192.168.2.102
fudge 192.168.2.102 stratum 1
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
#server 0.debian.pool.ntp.org iburst
#server 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst
# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255
# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines. Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient
答案1
像下面这样的东西应该有效。
restrict default ignore
restrict 127.0.0.1 nomodify
restrict 192.168.2.102 mask 255.255.255.0 nomodify notrap noquery
server 192.168.2.102 burst iburst
server 127.127.1.0
fudge 127.127.1.0 stratum 10
答案2
我确实让它工作了,所以对于后代来说,#ntp
(freenode)上有人说如果 B 没有报告自己已同步,机器 A 可能会不高兴。这可以通过ntpq -p
B 上不显示任何带有星号前缀的服务器来观察到。
捏造当地消息来源乙(通过检查系统时钟实际上确实同步)更正了:
server 127.127.1.0
fudge 127.127.1.0 stratum 10
然而,重要的是不是这样做A因为它比“本地同步”机器 B 更信任第 10 层。