NTP / PTP 仕様
43 / 43 items
InfraLab Reference Series
Category: NTP / PTP
Updated: 2026-05-14
infralab.jp
ntp-ptp
43 items
NTP / PTP 仕様
Abstract
NTPv4 の 48B ヘッダ、モード、Stratum、polling、chrony/ntpd、NTS、PTP メッセージ、クロック種別、BMCA、PHC 運用を整理。
Table of Contents
1. NTP 概要 (RFC 5905)
1.1. NTP とは
IP ネットワーク上でシステム時刻を同期するプロトコル。インターネット越しの汎用時刻同期に広く使われる。
NTPv4: RFC 5905。UDP/123。BCP: RFC 8633。Extension Fields: RFC 78221.2. NTP と PTP の使い分け
NTP は ms から十数 ms 級の汎用同期、PTP は LAN/専用網とハードウェアタイムスタンプで us/ns 級を狙う。
NTP: routed network friendly。PTP: IEEE 1588, L2/L3 multicast/unicast, PHC hardware timestamp1.3. NTS
Network Time Security は NTP の認証と改ざん耐性を TLS と AEAD cookie で提供する。
RFC 8915。NTS-KE: TCP/4460、NTP extension fields で cookie/authenticator2. NTP モード・パケット
2.1. NTP ヘッダ
NTP 基本ヘッダは 48B。LI/VN/Mode、Stratum、Poll、Precision、各種 timestamp を持つ。
48B: LI 2bit / VN 3bit / Mode 3bit / Stratum 8bit / Poll 8bit / Precision 8bit / Root Delay 32bit / Root Dispersion 32bit / Reference ID 32bit / 4 timestamps
RFC 5905 NTP Packet Header ASCII 図:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|LI | VN |Mode | Stratum | Poll | Precision |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Root Delay |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Root Dispersion |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reference ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reference Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reference Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Originate Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Originate Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Receive Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Receive Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Transmit Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Transmit Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+2.2. LI / Version / Mode
先頭 1B に leap indicator、NTP version、mode が詰め込まれる。
LI bits 7-6、VN bits 5-3、Mode bits 2-0。NTPv4 は VN=42.3. NTP Mode 1 / 2
Symmetric Active/Passive はピア同士が対等に同期する用途。現代の一般クライアント用途では少なめ。
Mode 1 = Symmetric Active、Mode 2 = Symmetric Passive2.4. NTP Mode 3 / 4
通常のクライアント/サーバ同期で使う mode。クライアントが mode 3、サーバ応答が mode 4。
Mode 3 = Client、Mode 4 = Server。UDP/1232.5. NTP Mode 5 / 6 / 7
Broadcast、Control、Private 用 mode。Control/Private は増幅攻撃対策で制限する。
Mode 5 Broadcast、Mode 6 Control、Mode 7 Private。monlist は古い ntpd のリスク2.6. Root Delay / Root Dispersion
上位参照源までの往復遅延と最大誤差見積もり。同期品質の判断材料になる。
Root Delay 32bit signed fixed-point、Root Dispersion 32bit unsigned fixed-point2.7. Reference ID
参照元を示す 32bit 値。Stratum 1 では ASCII、Stratum 2 以降では上位サーバ情報を表す。
Stratum 1 例: GPS, PPS。IPv4 server では IPv4 address、IPv6 では hash 等2.8. NTP Timestamps
4 つの 64bit timestamp で offset と delay を計算する。
Reference / Origin / Receive / Transmit timestamp。64bit seconds.fraction、epoch 1900-01-012.9. Offset / Delay 計算
クライアント送受信時刻とサーバ受送信時刻から時刻差と往復遅延を推定する。
offset = ((t2 - t1) + (t3 - t4)) / 2。delay = (t4 - t1) - (t3 - t2)3. Stratum・ポーリング
3.1. Stratum
参照源からの階層を示す。大きいほど遠く、16 は未同期を意味する。
Stratum 0: reference clock、1: directly attached、2-15: synchronized、16: unsynchronized3.2. Poll
ポーリング間隔は 2 の指数秒で表す。安定すると間隔を伸ばし、変動時は短くする。
minpoll 6 = 64s、maxpoll 10 = 1024s が既定例。Poll field は signed log2 seconds3.3. Precision
ローカルクロックの精度を 2 の指数秒で示す。値が小さいほど細かい。
Precision field signed log2 seconds。例 -20 は約 0.95 us3.4. Slew / Step
小さな時刻差は徐々に周波数調整し、大きな差は step で一気に補正する。
chrony makestep、ntpd panic threshold 1000s など実装依存。業務 DB では step timing に注意3.5. ntpd
伝統的な NTP 実装。多くの Unix で使われてきたが、近年は chrony へ移行する環境も多い。
ntpq -p / ntp.conf。Mode 6/7 制限設定が重要3.6. chronyd
変動環境や仮想環境、間欠接続に強い実装。Linux サーバで広く採用される。
chronyc sources -v / chronyc tracking / makestep / rtcsync3.7. systemd-timesyncd
軽量な SNTP クライアント。サーバ機能や高度な選択アルゴリズムは持たない。
timedatectl timesync-status。設定: /etc/systemd/timesyncd.conf4. PTP 概要 (IEEE 1588)
4.1. PTP とは
Precision Time Protocol。LAN や専用ネットワークで高精度時刻同期を行う IEEE 標準。
IEEE 1588v2 (2008)、IEEE 1588-2019。EtherType 0x88F7 または UDP/319, UDP/3204.2. PTP Event / General
時刻精度に影響する Event message と、管理・通知の General message でポートを分ける。
UDP/319 Event: Sync, Delay_Req, Pdelay_Req, Pdelay_Resp。UDP/320 General: Follow_Up, Delay_Resp, Announce, Management, Signaling4.3. One-step / Two-step
One-step は Sync に正確な timestamp を入れ、Two-step は Follow_Up で後から正確値を送る。
twoStepFlag=1 なら Sync + Follow_Up。Hardware timestamp 実装で選択4.4. E2E / P2P
End-to-End は master-slave 間遅延、Peer-to-Peer は隣接リンクごとの遅延を測る。
E2E: Delay_Req/Delay_Resp。P2P: Pdelay_Req/Pdelay_Resp/Pdelay_Resp_Follow_Up5. PTP メッセージ・クロック種別
5.1. PTP Common Header
IEEE 1588 PTPv2 の各 message に共通する 34B ヘッダ。Sync / Delay_Req もこのヘッダを持つ。
IEEE 1588 PTP common header ASCII 図:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ts | msg | res | ver | messageLength |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| domainNumber | reserved | flagField |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| correctionField |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| correctionField |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| sourcePortIdentity ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| sourcePortIdentity ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| portNumber | sequenceId |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| controlField | logMsgInt | Message Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+5.2. Sync
master から slave へ時刻基準を送る Event message。送信 timestamp が同期精度の中心。
MessageType 0x0。Event message、UDP/319 または L2 PTP
IEEE 1588 Sync message ASCII 図:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PTP Common Header ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| originTimestamp seconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| seconds | nanoseconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| nanoseconds | reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+5.3. Follow_Up
Two-step clock で Sync の正確な送信 timestamp を後続メッセージとして送る。
MessageType 0x8。preciseOriginTimestamp を含む5.4. Delay_Req / Delay_Resp
E2E 遅延測定で slave が Delay_Req を送り、master が受信時刻を Delay_Resp で返す。
Delay_Req type 0x1 (Event)、Delay_Resp type 0x9 (General)
IEEE 1588 Delay_Req message (Sync と同じ timestamp body) ASCII 図:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PTP Common Header ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| originTimestamp seconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| seconds | nanoseconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| nanoseconds | reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+5.5. Pdelay メッセージ
P2P 遅延測定で隣接ノード間の link delay を測る。
Pdelay_Req type 0x2、Pdelay_Resp type 0x3、Pdelay_Resp_Follow_Up type 0xA5.6. Announce
クロック品質、priority、identity を広告し、BMCA による Grandmaster 選出に使う。
MessageType 0xB。priority1, clockClass, clockAccuracy, offsetScaledLogVariance, priority2, grandmasterIdentity5.7. Management / Signaling
PTP 管理情報や unicast negotiation、プロファイル固有機能に使う General message。
Management type 0xD、Signaling type 0xC5.8. Ordinary Clock
単一 PTP port を持つ通常クロック。Grandmaster または slave として動作する。
OC。サーバ NIC/装置単体の PTP endpoint5.9. Boundary Clock
複数 PTP port を持ち、上流に同期し下流へ時刻を配る。ネットワーク機器で精度劣化を抑える。
BC。port ごとに master/slave 状態。各区間で PTP を終端5.10. Transparent Clock
PTP message の滞在時間を correctionField に加算し、スイッチ通過遅延を補正する。
TC。E2E Transparent / P2P Transparent5.11. Grandmaster
PTP ドメイン内の時刻源。GNSS、原子時計、上位時刻源に同期する。
BMCA で選出。clockClass/accuracy/priority が選定材料5.12. BMCA
Best Master Clock Algorithm。Announce 情報を比較し、最良の Grandmaster を選ぶ。
比較順: priority1, clockClass, clockAccuracy, offsetScaledLogVariance, priority2, clockIdentity6. 運用・トラブルシュート
6.1. PHC
PTP Hardware Clock。NIC 内部のハードウェアクロックを使い、software timestamp より高精度に同期する。
/dev/ptpN。確認: ethtool -T eth0、phc_ctl /dev/ptp0 get6.2. ptp4l
Linux PTP の主要デーモン。NIC PHC と PTP ネットワークを同期する。
ptp4l -i eth0 -m -H。設定: /etc/linuxptp/ptp4l.conf6.3. phc2sys
PHC とシステムクロックの間を同期する。ptp4l と組み合わせて OS 時刻へ反映する。
phc2sys -s /dev/ptp0 -c CLOCK_REALTIME -m。自動: phc2sys -a -r6.4. chronyc sources
NTP/chrony の参照元ごとの状態、到達性、offset、jitter を確認する。
chronyc sources -v。^* selected、^+ combined、^- not selected、Reach は octal reachability6.5. chronyc tracking
ローカルクロックの同期状態、stratum、system time、frequency、root delay/dispersion を見る。
chronyc tracking。System time、Last offset、RMS offset、Frequency、Skew、Root delay6.6. makestep
大きな時刻差を起動時などに step 補正する。常時 step はアプリケーション影響に注意する。
chronyc makestep。chrony.conf: makestep 1.0 36.7. PTP 能力確認
NIC とドライバが hardware timestamp と PHC をサポートするか確認する。
ethtool -T eth0。SOF_TIMESTAMPING_TX_HARDWARE / RX_HARDWARE / RAW_HARDWARE を確認6.8. 典型トラブルシュート
NTP は reach/offset/jitter、PTP は timestamp mode、domain、profile、VLAN/QoS、BC/TC 対応を確認する。
NTP: udp/123, stratum 16, firewall, leap。PTP: udp/319/320 or 0x88F7, domainNumber, delayMechanism, hardware timestamp, asymmetry7. References
- NTP
- PTP
- NTPv4
- RFC 5905
- RFC 8633
- RFC 7822
- RFC 8915
- IEEE 1588
- Stratum
- chrony
- chronyd
- ntpd
- systemd-timesyncd
- NTS
- Sync
- Follow_Up
- Delay_Req
- Delay_Resp
- BMCA
- Grandmaster
- PHC
- ptp4l
- phc2sys
- 時刻同期