動かざることバグの如し

近づきたいよ 君の理想に

Ubuntu 26.04でntpが廃止されたのでChronyに移行した

環境

  • Ubuntu 26.04

Ubuntu 26.04ではntpがインストールできない

Ubuntu 18.04以降はsystemd-timesyncdがデフォルトのタイムデーモンになっていたが、設定変更が面倒でそのままntpを使い続けていた。ところがUbuntu 26.04ではntpパッケージのインストール自体ができなくなってしまった。

root@70aa2e9ebfdf:/# apt install ntp
Package ntp is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  openntpd  ntpsec


Error: Package 'ntp' has no installation candidate

調べてみるとUbuntu 25.10以降でデフォルトのタイムデーモンがsystemd-timesyncdからChronyに置き換わったらしい。つまりUbuntu 26.04ではChronyが標準になったということだ。 さすがにこれ以上抵抗するのも無理があるので、重い腰を上げてChronyを試してみることにした。

ソース

ubuntu.com

Chrony is replacing systemd-timesyncd as the default in Ubuntu 25.10 and ntpdate/ntpd, which was the default before Ubuntu 18.04 LTS.
On upgraded systems (from Ubuntu 25.04 or below) systemd-timesyncd might still be the active time-daemon and thus render the new chrony service disabled.
Similarly, while the use of ntpd is no longer recommended, it might still be installed to retain any previous behavior/config on upgrades (up to Ubuntu 22.04 LTS).

確認

すでにインストール済みで動作している。systemctl status chrony.service で動作確認可能

# systemctl status chrony.service
● chrony.service - chrony, an NTP client/server
     Loaded: loaded (/usr/lib/systemd/system/chrony.service; enabled; preset: enabled)
     Active: active (running) since Thu 2026-06-18 18:55:22 JST; 17h ago
 Invocation: 0f9bf8c093d941a59e51c4eacefc2eb1
       Docs: man:chronyd(8)
             man:chronyc(1)
             man:chrony.conf(5)
   Main PID: 1246 (chronyd-starter)
      Tasks: 3 (limit: 3525)
     Memory: 10.8M (peak: 11M)
        CPU: 317ms
     CGroup: /system.slice/chrony.service
             ├─1246 /bin/sh /usr/lib/systemd/scripts/chronyd-starter.sh -n -F 1
             ├─1332 /usr/sbin/chronyd -n -F 1
             └─1355 /usr/sbin/chronyd -n -F 1

chronyc sourcesはChronyが参照しているNTPサーバの一覧を表示するコマンドだ。

MSはModeと状態を示す。^*が現在選択中のソース、^+は補助的に利用されているソース、^-は候補だが選択されていないソース

# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp-nts-2.ps5.canonical.>     2  10   377   726    +20ms[  +20ms] +/-  113ms
^+ ntp-nts-3.ps5.canonical.>     2  10   377   754    +20ms[  +20ms] +/-  113ms
^+ ntp-nts-2.ps6.canonical.>     2  10   377   669    -21ms[  -21ms] +/-  154ms
^+ ntp-nts-3.ps6.canonical.>     2  10   377   734    -27ms[  -27ms] +/-  152ms
^- ntp-nts-1.ps6.canonical.>     2  10   377   188    -28ms[  -28ms] +/-  152ms

chronyc trackingは現在のNTP同期状態の詳細を表示するコマンドだ。

  • Reference ID: 参照しているNTPサーバのIPアドレスとホスト名
  • Stratum: 現在のstratum値。NTPサーバがstratum 2なので、クライアントはstratum 3になる
  • System time: NTP時刻に対してシステム時刻がどれだけずれているか
  • Last offset: 最後の更新で補正されたオフセット
  • Frequency: クロックの周波数誤差(ppm)。OSのクロックが若干速い/遅い場合の補正値として使われる
  • Root delay / Root dispersion: 参照時計からの遅延と分散。ネットワーク品質を示す

またchronyc makestepは時刻のずれを即座に強制補正するコマンドだ。通常Chronyはゆっくりと時刻をスルー調整するが、このコマンドを使うと即座にステップ補正する。実行後のtrackingを見るとSystem time0.000000000 secondsになっており、補正が完了していることが確認できる。

# chronyc tracking
Reference ID    : B97DBE7A (ntp-nts-2.ps5.canonical.com)
Stratum         : 3
Ref time (UTC)  : Fri Jun 19 02:58:42 2026
System time     : 0.000699921 seconds fast of NTP time
Last offset     : -0.000062693 seconds
RMS offset      : 0.000555336 seconds
Frequency       : 0.031 ppm slow
Residual freq   : +0.000 ppm
Skew            : 0.016 ppm
Root delay      : 0.219320118 seconds
Root dispersion : 0.001305242 seconds
Update interval : 1039.8 seconds
Leap status     : Normal

# chronyc makestep
200 OK

# chronyc tracking
Reference ID    : B97DBE7A (ntp-nts-2.ps5.canonical.com)
Stratum         : 3
Ref time (UTC)  : Fri Jun 19 02:58:42 2026
System time     : 0.000000000 seconds slow of NTP time
Last offset     : -0.000062693 seconds
RMS offset      : 0.000555336 seconds
Frequency       : 0.031 ppm slow
Residual freq   : +0.000 ppm
Skew            : 0.016 ppm
Root delay      : 0.219320118 seconds
Root dispersion : 0.001325135 seconds
Update interval : 1039.8 seconds
Leap status     : Normal

サーバー設定は /etc/chrony/sources.d/ubuntu-ntp-pools.sources で可能。

# cat /etc/chrony/sources.d/ubuntu-ntp-pools.sources
# Use NTS by default
# NTS uses an additional port to negotiate security: 4460/tcp
# The normal NTP port remains in use: 123/udp
pool 1.ntp.ubuntu.com iburst maxsources 1 nts prefer
pool 2.ntp.ubuntu.com iburst maxsources 1 nts prefer
pool 3.ntp.ubuntu.com iburst maxsources 1 nts prefer
pool 4.ntp.ubuntu.com iburst maxsources 1 nts prefer
# The bootstrap server is needed by systems without a hardware clock, or a very
# large initial clock offset. The specified certificate set is defined in
# /etc/chrony/conf.d/ubuntu-nts.conf.
pool ntp-bootstrap.ubuntu.com iburst maxsources 1 nts certset 1
  • pool: NTPサーバのプールを指定するディレクティブ。DNSで複数のIPアドレスに解決されるホスト名を使用する
  • iburst: 初回同期時に連続してパケットを送信し、素早く同期させるオプション
  • maxsources 1: プールから使用するサーバ数の上限。各プールから1台ずつ選ぶことで合計4〜5台を参照する構成になっている
  • nts: NTS(Network Time Security)を使用するオプション。通信を暗号化・認証しなりすましを防ぐ。追加でTCPポート4460番を使用する
  • prefer: 同等の優先度なら、このサーバを優先して選択する
  • ntp-bootstrap.ubuntu.com: ハードウェアクロックを持たないシステムや、初期時刻が大幅にずれているシステム向けのブートストラップサーバ。certset 1で専用の証明書セットを使用する(/etc/chrony/conf.d/ubuntu-nts.confで定義)

参考リンク