Ntp

使用本地 NTP 服務

  • January 7, 2015

我正在嘗試讓一個沒有外部 Internet 訪問權限的系統 (A) 從 LAN 上的另一個系統獲取時間 (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

如果我在 A 上停下ntpd來嘗試ntpd -gq,我可以再次在 Wireshark 中來回觀看,但一兩分鐘後,命令超時並顯示“未找到伺服器”。

我什至嘗試添加到 A 的 conf:

fudge 192.168.2.102 stratum 1

沒有任何區別。

如何強制 ntpd 從特定伺服器設置時間? 看起來這曾經很容易使用ntpdate——它已被折舊並且在系統上不存在。


這是機器 A 的整個 ntp.conf。這是庫存的 Debian wheezy。我所做的唯一更改是添加涉及 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

我確實讓它工作了,所以對於後代來說,#ntp(freenode)上的某個人說,如果 B 不報告自己已同步,機器 A 可能會不高興。這可以通過ntpq -p在 B 上觀察到,沒有顯示任何帶有星號前綴的伺服器。

在B上偽造一個本地源(通過檢查系統時鐘實際上是同步的)糾正了這一點:

server 127.127.1.0
fudge  127.127.1.0 stratum 10

但是,重要的是不要A上執行此操作,因為它會比認為“本地同步”機器 B 更信任第 10 層。

像下面這樣的東西應該​​可以工作。

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

引用自:https://unix.stackexchange.com/questions/177999