Introduction
インターネットにつながっていない、閉域 LAN 内の iPhone の時刻を正確に同期する方法について。
Qita 等でそれなりに記事があるが、ざっくりとした記事が多く、わかりづらいと思ったので試してみた。
How to resolve?
環境は下記
| サブネット | IP | ホスト名 | OS | |
|---|---|---|---|---|
| NTP サーバ兼 DNS サーバ | 192.168.11.0/24 | 192.168.11.185 | VM999 | Ubuntu 24.04 LTS |
| クライアント 1 | 192.168.11.0/24 | 192.168.11.15 | - | iOS 15.8.6 (iPhone 7 Plus) |
| クライアント 2 | 192.168.11.0/24 | 192.168.11.49 | - | iOS 26.3.1 (iPhone SE3) |
NTP サーバの構築
1. chrony のインストール
1 | $ sudo apt install chrony |
2. /etc/chrony/chrony.conf の編集
pool と server は使わないことで自分自身の時刻を配るように設定。
1 | - pool ntp.ubuntu.com iburst maxsources 4 |
3. chrony の起動及び動作確認
1 | $ sudo systemctl restart chrony |
NTP サーバ上で下記を実行し、chrony が動作していることを確認
1 | $ chronyc tracking |
同一ネットワークの別マシンからも動作を確認。
1 | $ sudo apt install ntpsec-ntpdate |
もしここで、 ntpdig: no eligible servers と帰ってきたら、NTP サーバと通信できていないので、NTP サーバのファイヤーウォールか /etc/chrony/chrony.conf の allow が間違っているので確認する。
DNS サーバの構築
1. dnsmasq のインストール
1 | $ sudo apt install dnsmasq |
2. /etc/dnsmasq.conf の編集
1 | - #conf-dir=/etc/dnsmasq.d/,*.conf |
3. /etc/dnsmasq.d/override-apple-ntp.conf の作成
ファイル名は *.conf であれば何でもよい。
別のマシンへの問い合わせも不要にしてある。
1 | no-dhcp-interface=eth0 |
4. /etc/hosts の編集
/etc/dnsmasq.conf で no-hosts をコメントアウトしたままなので、 /etc/hosts を編集するだけで名前解決をできるようにする。
1 | + 192.168.11.185 time.apple.com |
上記の Apple の NTP サーバのうち、使うのは一部だけだが念のため記載。
5. dnsmasq の起動及び動作確認
まず、 systemd-resolved を停止してから起動。
1 | $ sudo systemctl disable systemd-resolved |
これを実施しないと、下記のように、dnsmasq 起動に失敗する。
1 | $ sudo systemctl restart dnsmasq |
同一ネットワーク上の別マシン (192.168.11.115) から名前解決を確認。
1 | $ ip -4 a | grep inet |
ログを見ると、192.168.11.115 から問い合わせが来ていることが確認できる。
1 | $ sudo tail -f /var/log/dnsmasq/dnsmasq.log |
iPhone から時刻同期
モバイルデータ通信を停止し、NTP サーバと同一のネットワークの Wi-Fi に接続。
DNS を手動に変更。
NTP サーバ兼 DNS サーバの IP を指定。
NTP サーバ上で時刻を強制変更。
1 | $ sudo timedatectl set-ntp no |
しばらくして、iPhone 上の時刻設定における 自動設定 の ON/OFF を切り替えると、時刻が主導してい時刻になっていることがわかる。
確認ができたら自動設定にすればよい。
NTP サーバ上の dnsmasq に対する名前解決の問い合わせが iPhone からきていることがわかる。
1 | sudo tail -f /var/log/dnsmasq/dnsmasq.log | grep time |
下記は実際の変化の様子。
すぐに自動設定を切り替えても時刻の更新が走らないため、30 秒ほどたってから切り替えを行っている。





