6
5

More than 3 years have passed since last update.

閉じられたネットワーク内のiPadを自動で時刻調整できるように設定する

Last updated at Posted at 2020-11-29

概要

インターネット接続のないLAN内にいるiPadの時刻が徐々にずれてきたので、時刻設定を自動でできるようにしてみた。

MacやiOSで使用するNTPサーバのFQDNはエンタープライズネットワークで Apple 製品を使う - Apple サポートで確認できるので、LAN内にDNSサーバとNTPサーバを設置し、LAN内に設置したNTPサーバを指すようにDNSレコードを設定すればよい。

設定

閉じられたネットワークとインターネットの両方に接続できるマシンを準備。
今回は下記の設定。

  • OS: Ubuntu 20.04.1 LTS
  • IP:
    • (閉じられたネットワーク側)192.168.20.199/24
    • (インターネットに接続できる側)DHCP

unboundのインストールと設定

今回はDNSサーバとしてunboundを仕様(bindだと設定が面倒すぎた)。

sudo apt install unbound -y

設定ファイルは下記のように設定。

/etc/unbound/unbound.conf.d/unbound.conf
server:
        verbosity: 1
        interface: 192.168.20.199
        access-control: 192.168.20.0/24 allow
        use-syslog: yes # DNSクエリの監視用
        log-queries: yes #

        local-data: "time.apple.com IN A 192.168.20.199"
        local-data: "time-ios.apple.com IN A 192.168.20.199"
        local-data: "time-macos.apple.com IN A 192.168.20.199"

python:

remote-control:

forward-zone:
        name: "."
        forward-addr: 8.8.8.8
        forward-addr: 8.8.4.4

time.apple.comtime-ios.apple.comtime-macos.apple.comのAレコードはNTPサーバのIPアドレスを指定する(iPadならtime-macosは不要のはずだけど、とりあえず)。
今回は同一マシンにDNSサーバとNTPサーバを立てるのでinterfaceと同じアドレスを指定しているが、すでに他のNTPサーバがあるならそちらのIPアドレスを指定する。

use-syslog: yeslog-queries: yesはiPadからのDNSクエリを確認するために設定。
上手くいったあとは削除して良い。

設定ファイルの編集が済んだらサービスを再起動。

sudo systemctl restart unbound

NTPサーバのインストールと設定

次にNTPサーバをインストールして設定。

sudo apt install ntp -y

完全に好みだが、基準とするNTPサーバはUbuntuのデフォルトで用意されているものをすべてコメントアウトしてINTERNET MULTIFEED CO.で用意されているものを利用した。

/etc/ntp.conf
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com

ちなみに、LXDなどコンテナでNTPサーバを起動する時は、時刻合わせはホスト側が行うので、以下のように自分のローカル時刻を使うよう指定する。stratumの値は15以下のお好みの値で。

/etc/ntp.conf
server 127.127.1.0 prefer
fudge 127.127.1.0 stratum 10

こちらも設定後にサービス再起動。

sudo systemctl restart ntp

NTPサーバの動作確認のため、ntpdateをインストールして確認。

sudo apt install ntpdate
$ sudo ntpdate -q 192.168.20.199
server 192.168.20.199, stratum 3, offset -0.000027, delay 0.02574
27 Nov 06:08:09 ntpdate[5915]: adjust time server 192.168.20.199 offset -0.000027 sec

iPadの設定

iPadのWi-Fi設定で、DNSサーバを「手動」で「192.168.20.199」(今回の例では)に設定。

確認していないが、もしDHCPを使用しているなら、DHCPサーバのオプションでDNSサーバを192.168.20.199に設定すれば大丈夫なはず。

あとはしばらく待てばtime-ios.apple.comへのDNSクエリが来て、自動で時刻が調整されているはず。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5