0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Androidが使うNTPサーバーアドレスを変更する

0
Last updated at Posted at 2026-02-21

AOSPのAndroidでは、デフォルトのNTPサーバーはtime.android.com (メーカーによってはpool.ntp.orgなど) になっています。イントラネットなどではNTPサーバーを参照できず、徐々に時刻がずれていってしまうので、この記事ではAndroidで参照するNTPサーバーアドレスを変更する方法を解説します。

必要なもの

  • Android (おそらく)5.0以降が搭載された端末(Rootは必要ないはずです。)
  • ADBが使えるPC

現在設定されているNTPサーバー名を確認する

adb shell settings get global ntp_server

結果がnullだった場合はNTPサーバーは明示的に設定されていません。(デフォルトのNTPが参照されます。time.android.comなど。)サーバーアドレスが返ってきた場合はそのNTPサーバーを参照するように設定されています。

同期状態や詳細情報を確認する

adb shell dumpsys network_time_update_service

結果の例:

 >adb shell dumpsys network_time_update_service
mDefaultNetwork=131   //現在時刻同期に使われているNWのID(Wi-Fiやモバイル回線、VPNなど)
mNormalPollingIntervalMillis=64800000   //時刻同期の間隔(この例では18時間おき)
mShortPollingIntervalMillis=60000   //時刻同期失敗時の再試行間隔(この例だと1分後)
mTryAgainTimesMax=3   //時刻同期失敗時のリトライ回数(この例では3回。)
mLastRefreshAttemptElapsedRealtimeMillis=PT20.974S (20974)   //端末起動時から計算した最後の時刻同期時間(この例では端末起動20.974秒後に同期)
mTryAgainCounter=0   //現在の再試行回数(この例では0回)

NtpTrustedTime:
  getNtpConfig()=NtpConnectionInfo{mServerUris=[ntp://time.android.com], mTimeout=PT5S}   //現在使用しているNTPサーバーアドレスとタイムアウト時間(この例ではNTPサーバーはtime.android.com / タイムアウト5秒)
  mNtpConfigForTests=null   //テスト用NTPサーバー
  mLastSuccessfulNtpServerUri=ntp://time.android.com   //最後に時刻同期に成功したサーバー
  mTimeResult=TimeResult{unixEpochTime=2026-02-21T04:08:52.617Z, elapsedRealtime=PT21.146S, mUncertaintyMillis=43, mNtpServerSocketAddress=time.android.com/[2001:4860:4806:8::]:123}   //最後に取得した時刻の詳細情報
  mTimeResult.getAgeMillis()=PT11H11M57.506S   //最後に取得した時刻情報の経過時間

Debug log:
  PT2H15M15.158S / 2026-02-21T06:23:45.185313Z - refreshIfRequiredAndReschedule: network=100, reason=network available, initialTimeResult=TimeResult{unixEpochTime=2026-02-21T04:08:52.617Z, elapsedRealtime=PT21.146S, mUncertaintyMillis=43, mNtpServerSocketAddress=time.android.com/[2001:4860:4806:8::]:123}, shouldAttemptRefresh=false, refreshSuccessful=false, currentElapsedRealtimeMillis=PT2H15M15.156S (8115156), latestTimeResult=TimeResult{unixEpochTime=2026-02-21T04:08:52.617Z, elapsedRealtime=PT21.146S, mUncertaintyMillis=43, mNtpServerSocketAddress=time.android.com/[2001:4860:4806:8::]:123}, mTryAgainCounter=0, refreshAttemptDelayMillis=64800000, nextRefreshElapsedRealtimeMillis=PT18H21.146S (64821146)
Debug欄の各要素の意味

unixEpochTime=2026-02-21T04:08:52.617Z

取得したUTC時刻 (ZはUTCの意味)

elapsedRealtime=PT21.146S

端末起動後21.146秒の時点で取得

mUncertaintyMillis=43

推定誤差 ±43ミリ秒

mNtpServerSocketAddress=time.android.com/[2001:4860:4806:8::]:123

接続した実際のIPアドレス(この例ではIPv6アドレスのポート123)

端末の起動から時間が経っている(=過去何度も時刻同期している)場合、Debugログが非常に長くなる場合があります。

使用するNTPを変更する

adb shell settings put global ntp_server pool.ntp.org

再起動しないと反映されません。adb reboot

NTP確認 正しく書き換わっていることが確認できます。
 >adb shell settings get global ntp_server 
pool.ntp.org

 >adb shell dumpsys network_time_update_service
mDefaultNetwork=102
mNormalPollingIntervalMillis=64800000
mShortPollingIntervalMillis=60000
mTryAgainTimesMax=3
mLastRefreshAttemptElapsedRealtimeMillis=PT21.724S (21724)
mTryAgainCounter=0

NtpTrustedTime:
  getNtpConfig()=NtpConnectionInfo{mServerUris=[ntp://pool.ntp.org], mTimeout=PT5S}
  mNtpConfigForTests=null
  mLastSuccessfulNtpServerUri=ntp://pool.ntp.org
  mTimeResult=TimeResult{unixEpochTime=2026-02-21T15:46:43.870Z, elapsedRealtime=PT26.865S, mUncertaintyMillis=26, mNtpServerSocketAddress=pool.ntp.org/[2001:db8::]:123}
  mTimeResult.getAgeMillis()=PT1M54.505S

Debug log:
  PT26.875S / 2026-02-21T15:46:42.128624Z - refreshIfRequiredAndReschedule: network=100, reason=network available, initialTimeResult=null, shouldAttemptRefresh=true, refreshSuccessful=true, currentElapsedRealtimeMillis=PT26.866S (26866), latestTimeResult=TimeResult{unixEpochTime=2026-02-21T15:46:43.870Z, elapsedRealtime=PT26.865S, mUncertaintyMillis=26, mNtpServerSocketAddress=pool.ntp.org/[2001:db8::]:123}, mTryAgainCounter=0, refreshAttemptDelayMillis=64800000, nextRefreshElapsedRealtimeMillis=PT18H26.865S (64826865)
  PT43.384S / 2026-02-21T15:46:58.638091Z - refreshIfRequiredAndReschedule: network=102, reason=network available, initialTimeResult=TimeResult{unixEpochTime=2026-02-21T15:46:43.870Z, elapsedRealtime=PT26.865S, mUncertaintyMillis=26, mNtpServerSocketAddress=pool.ntp.org/[2001:db8::]:123}, shouldAttemptRefresh=false, refreshSuccessful=false, currentElapsedRealtimeMillis=PT43.379S (43379), latestTimeResult=TimeResult{unixEpochTime=2026-02-21T15:46:43.870Z, elapsedRealtime=PT26.865S, mUncertaintyMillis=26, mNtpServerSocketAddress=pool.ntp.org/[2001:db8::]:123}, mTryAgainCounter=0, refreshAttemptDelayMillis=64800000, nextRefreshElapsedRealtimeMillis=PT18H26.865S (64826865)

設定したNTPサーバーを消去する

adb shell settings delete global ntp_server

再起動して完了です。これで元のNTPを参照してくれます。

最後に

最初は端末の時刻を手動でわざとずらし、その後「インターネットで時刻を同期する。」のトグルをON/OFFしましたが、NTP同期はされていませんでした。なのでAndroidでは意図的に時刻をずらしても内部に正しい時刻をちゃんと保持しているようです。
因みにtime.android.comはGoogleのNTPサーバーtime.google.comとIP帯が同じなので、内部的にはおそらく同じサーバーです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?