config ntp サブコマンド¶
概要¶
config ntp は NTP サーバ(chrony で動作)の追加・削除を行う CLI グループ。CONFIG_DB の NTP_SERVER テーブルを直接書き換え、chrony サービスを再起動する1。
SONiC では NTP daemon として chrony を採用しており、config ntp で NTP_SERVER テーブルを書くと chrony.conf テンプレートが再生成され、systemctl restart chrony で反映される。
コマンド一覧¶
| コマンド | 用途 |
|---|---|
config ntp add <ntp_ip_address> [options] |
NTP サーバ追加 |
config ntp del <ntp_ip_address> |
NTP サーバ削除 |
各コマンドの詳細¶
config ntp add <ntp_ip_address> [options]¶
用法:
引数:
<ntp_ip_address>... NTP サーバの IP アドレス。--association-type server(デフォルト) の場合はclicommon.is_ipaddressで IP 検証。poolの場合は FQDN を許容する。
オプション:
--association-type {server,pool}... デフォルトserver。pool指定時は chrony のpoolディレクティブで構成される。--iburst... 起動直後の高頻度同期を有効化(iburst on)。--version <int>... NTP プロトコルバージョン指定。
動作:
ADHOC_VALIDATIONが真のとき、IP 検証を実施 (association_type != "pool"の場合)- 既存
NTP_SERVERテーブルを取得し、同 IP が既存ならNTP server <ip> is already configuredで no-op return - options を辞書化(version / association_type / iburst)し、
db.set_entry('NTP_SERVER', <ip>, opts)で CONFIG_DB に書く systemctl restart chronyを実行。失敗時はctx.fail
📋 検証エビデンス: sonic-net/sonic-utilities/config/main.py#L8982-L9016 (sha: 39732bceb8bdefe706518ab40623bbbba6ff33b9)
出典:
sonic-net/sonic-utilities/config/main.py#L8982-L9016 (sha: 39732bceb8bdefe706518ab40623bbbba6ff33b9)
抜粋:
@ntp.command('add')
def add_ntp_server(ctx, ntp_ip_address, association_type, iburst, version):
if ADHOC_VALIDATION:
if not clicommon.is_ipaddress(ntp_ip_address) and association_type != "pool":
ctx.fail('Invalid IP address')
...
db.set_entry('NTP_SERVER', ntp_ip_address, ntp_server_options)
...
clicommon.run_command(['systemctl', 'restart', 'chrony'], display_cmd=False)
config ntp del <ntp_ip_address>¶
用法:
動作:
- 既存
NTP_SERVERテーブルを取得、未登録 IP ならNTP server <ip> is not configured.でエラー終了 db.set_entry('NTP_SERVER', <ip>, None)で entry を削除systemctl restart chronyを実行
関連する CONFIG_DB¶
| テーブル | キー | フィールド |
|---|---|---|
NTP_SERVER |
<ip_or_fqdn> |
version, association_type, iburst |
注意¶
- 既存 IP に再度
addしてもオプションは更新されない(早期 return する)。オプション変更は一度delしてから再addする。 - chrony 再起動が伴うため、SSH や BGP 等が NTP に依存している場合は短時間のタイムスタンプ揺らぎがありうる。
データフロー (自動生成)¶
flowchart LR
CLI["config ntp"]
SC["sonic-cfggen<br/>(config CLI のみ)"]
CLI --> SC
CDB0[("CONFIG_DB<br/>NTP_SERVER")]
SC --> CDB0
DM0["ntp-config"]
CDB0 --> DM0
凡例
config 系 (CLI → CONFIG_DB → daemon) のミニ図。テーブル → daemon 対応は docs/reference/config-db-orch-map.md から機械生成。
関連リファレンス¶
引用元¶
実行例¶
典型的な使い方¶
よくある引数の組み合わせ¶
sudo config ntp del 10.0.0.10
# Management VRF 経由で NTP を引く
sudo config ntp add 10.0.0.10 --association-type pool
期待される出力 (抜粋)¶
運用ヒント¶
典型的な利用シーン¶
- NTP server 追加・削除、VRF (mgmt) 越し設定。
- 時刻同期失敗の調査前段。
よくある落とし穴¶
- mgmt VRF を使う環境で
config ntp addに VRF オプションを忘れると到達できない。 - chronyc / ntpq の出力差で「同期済み」判定がズレる。
show ntpが mgmt VRF + vrf=default 設定で空出力または "Invalid VRF name" になる (issue #4400): mgmt VRF が有効でNTP|global.vrf = "default"を設定している場合、chronyd-starter.shはデフォルト VRF で chrony を起動するがshow ntpは常に mgmt VRF 経由でchronycを呼ぶため VRF が食い違う。回避策:ip vrf exec default chronyc tracking/ip vrf exec default chronyc sourcesで直接確認する。- tab 補完が機能しない環境がある (issue #4398):
bash-completionパッケージがsonic-utilities-dataのSuggests(非Depends) のため、deb バージョンピニングなしのビルドでは未インストールになりうる。確認:dpkg -l bash-completionがunの場合はsudo apt-get install bash-completion && source /etc/bash_completionで手動インストールする。
関連する show / debug¶
関連 CLI コマンド¶
show clock— show clock サブコマンドshow environment— show environment サブコマンドshow feature— show feature サブコマンドshow platform— show platform サブコマンドshow services— show services サブコマンド
関連ページ¶
-
config ntpグループ定義はconfig/main.pyL8968-L9037。https://github.com/sonic-net/sonic-utilities/blob/39732bceb8bdefe706518ab40623bbbba6ff33b9/config/main.py#L8968 ↩