NTPd 多播設定

NTPd 多播設定

我需要設定一個 ntp 多播客戶端。為了能夠檢查我的配置是否良好,我嘗試設定 NTP 多播伺服器。

我的設定:

  • 2 個 Centos 7 虛擬機,最新
  • 我在 virtualbox 中使用 2 個虛擬機,我都使用 promicius 模式設定了兩個虛擬機:允許所有

我的問題是:

  • 在伺服器上,組播表項報告為層16;層與多播相關嗎?客戶會因為層次低而拒絕嗎?如何強制組播伺服器使用較低層?
  • 我的客戶似乎沒有我的伺服器,即使我的密鑰檔案相同並且我雙方都信任密鑰 1。

使用孤兒指令,似乎並沒有降低多播位址的報告層:

ntpq -n -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.165.10.2    192.165.10.109   4 u   14   64  377    0.454    2.267   1.479
 224.0.1.1       .MCST.          16 u    -   64    0    0.000    0.000   0.000

我的客戶端似乎仍然無法在 224.0.1.1 位址上找到伺服器。

我檢查了伺服器虛擬機、我的主機和客戶端虛擬機,它們都看到伺服器多播訊息(對於虛擬機:使用 tcpdump,對於主機:使用wireshark)。

在客戶端,使用ntpq -n -p將傳回:

No association ID's returned

在客戶端上,我的設定檔註解了所有限制指令,而我只有這些(還有一些像driftfile之類的):

multicastclient 224.0.1.1
keys /etc/ntp/keys
trustedkey 1

ntpd 客戶端日誌給了我這個:

systemd[1]: Starting Network Time Service...
ntpd[11076]: ntpd [email protected] Tue Jun 23 15:38:18 UTC 2020 (1)
systemd[1]: Started Network Time Service.
ntpd[11077]: proto: precision = 0.052 usec
ntpd[11077]: 0.0.0.0 c01d 0d kern kernel time sync enabled
ntpd[11077]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
ntpd[11077]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
ntpd[11077]: Listen and drop on 1 v6wildcard :: UDP 123
ntpd[11077]: Listen normally on 2 lo 127.0.0.1 UDP 123
ntpd[11077]: Listen normally on 3 enp0s3 192.165.10.107 UDP 123
ntpd[11077]: Listen normally on 4 lo ::1 UDP 123
ntpd[11077]: Listen normally on 5 enp0s3 fe80::a00:27ff:fec1:cc1 UDP 123
ntpd[11077]: Listening on routing socket on fd #22 for interface updates
ntpd[11077]: Listen normally on 6 multicast 224.0.1.1 UDP 123
ntpd[11077]: Joined 224.0.1.1 socket to multicast group 224.0.1.1
ntpd[11077]: 0.0.0.0 c016 06 restart
ntpd[11077]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
ntpd[11077]: 0.0.0.0 c011 01 freq_not_set
ntpd[11077]: io_setbclient: Opened broadcast client on interface #3 enp0s3

答案1

層 16 表示 NTP 伺服器不相信它具有有效時間,因為它沒有連接到任何配置的時間來源。為了使ntpd伺服器系統信任系統的本地時鐘作為時間來源,有兩種選擇:

  • 現代方法是在多播伺服器上的檔案中指定tos orphan和關鍵字。tos orphanwaitntp.conf
# If orphaned, serve others with this stratum.
tos orphan 8
# Wait for this many seconds before starting to serve others (default is 300 s)
tos orphanwait 1
  • 較舊的方法是告訴ntpd使用本地時鐘作為多播伺服器上的假時間來源。這個配置不應與真實 NTP 時間源一起使用,因為它可能會導致ntpd相信本地時鐘而不是真實的 NTP 來源,除非已配置足夠數量的外部來源並且彼此之間足夠同步以投票淘汰 127.127.1.0 偽源(這是總是與本地時鐘完全一致,因此它往往會受到ntpd選擇演算法的過度青睞)。
server 127.127.1.0 iburst
fudge 127.127.1.0 stratum 8

以 開頭的 IP 位址127.127.*是特殊的ntpd:它們指的是內建於 中的各種參考時脈驅動程式ntpd

這兩種方法都會使系統基於使用第8 層的NTP 上的本地不同步系統時脈來提供UTC 時間,因此任何與真實NTP 時間源(= 層7 或更少)有相當直接連接的系統都應該更喜歡它。

只要您的版本支援它,建議使用較新的方法ntpd,因為使用它,如果/當您向系統添加真正的 NTP 時間源時,您不必記住刪除偽源。

相關內容