![使用本地NTP服務](https://rvso.com/image/36015/%E4%BD%BF%E7%94%A8%E6%9C%AC%E5%9C%B0NTP%E6%9C%8D%E5%8B%99.png)
我試圖讓一個沒有外部網際網路存取的系統(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。我所做的唯一更改是添加涉及 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 層。