とりあえずローカルで安定した時刻を貰えるように。
/etc/ntp.conf
# Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. #restrict default nomodify notrap noquery restrict default ignore # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 # -- CLIENT NETWORK ------- # Permit systems on this network to synchronize with this # time service. Do not permit those systems to modify the # configuration of this service. Also, do not use those # systems as peers for synchronization. # restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap restrict 192.168.0.0 mask 255.255.255.0 nomodify nopeer notrap # --- OUR TIMESERVERS ----- #server 0.pool.ntp.org #server 1.pool.ntp.org #server 2.pool.ntp.org restrict 210.139.246.140 nomodify noquery notrap # ntp01.so-net.ne.jp restrict 202.238.95.20 nomodify noquery notrap # ntp02.so-net.ne.jp restrict 133.243.238.163 nomodify noquery notrap # ntp.nict.jp restrict 133.243.238.164 nomodify noquery notrap # ntp.nict.jp restrict 133.243.238.243 nomodify noquery notrap # ntp.nict.jp restrict 133.243.238.244 nomodify noquery notrap # ntp.nict.jp server -4 ntp01.so-net.ne.jp minpoll 6 maxpoll 10 prefer server -4 ntp02.so-net.ne.jp minpoll 6 maxpoll 10 prefer server -4 ntp.nict.jp minpoll 6 maxpoll 10 server -4 ntp.nict.jp minpoll 6 maxpoll 10 server -4 ntp.nict.jp minpoll 6 maxpoll 10 # --- NTP MULTICASTCLIENT --- #multicastclient # listen on default 224.0.1.1 # restrict 224.0.1.1 mask 255.255.255.255 nomodify notrap # restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # --- GENERAL CONFIGURATION --- # # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. The # default stratum is usually 3, but in this case we elect to use stratum # 0. Since the server line does not have the prefer keyword, this driver # is never used for synchronization, unless no other other # synchronization source is available. In case the local host is # controlled by some external source, such as an external oscillator or # another protocol, the prefer keyword would cause the local host to # disregard all other synchronization sources, unless the kernel # modifications are in use and declare an unsynchronized condition. # #server 127.127.1.0 # local clock #fudge 127.127.1.0 stratum 10 # # Drift file. Put this in a directory which the daemon can write to. # No symbolic links allowed, either, since the daemon updates the file # by creating a temporary in the same directory and then rename()'ing # it to the file. # driftfile /var/lib/ntp/drift logfile /var/log/ntp.log broadcastdelay 0.008 # # Keys file. If you want to diddle your server at run time, make a # keys file (mode 600 for sure) and define the key number to be # used for making requests. # # PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote # systems might be able to reset your clock at will. Note also that # ntpd is started with a -A flag, disabling authentication, that # will have to be removed as well. # keys /etc/ntp/keys
まずプロバイダが so-net なので、適当に dig ntp.so-net.ne.jp とやったら 210.139.246.140 が返ってきて、dig -x 210.139.246.140 とやったら ntp01.so-net.ne.jp だったので、ntp02.so-net.ne.jp もありそうということで設定ファイルに書いてみた。設定ファイルの restrict には IP アドレスで記述する必要がある*1。ntp.so-net.ne.jp は stratum 2 だが、ntp.nict.jp は stratum 1。stratum 1 に負荷をかけるのは良くないだろうということで、server 文の ntp.so-net.ne.jp には prefer を付け、優先的に問い合わせるようにしてみた*2。
この上で sudo service ntpd start する。restrict 192.168.0.0 の行で、ローカルネットワークの時刻問い合わせに対して応答するように設定している。しかしデーモン起動後の最初の 5 分ほどは、ntpd が問い合わせるサーバとの時刻同期が完了していないと判断し、時刻情報を提供しない。
ntpq NTP_SERVER
% ntpq NTP_SERVER
ntpq> pe
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp01.so-net.ne 210.132.247.45 2 u 8 64 1 7.995 -8.138 0.015
ntp-a3.nict.go. .INIT. 16 u - 64 0 0.000 0.000 4000.00
ntp-a3.nict.go. .PPS. 1 u 7 64 1 8.674 0.092 0.015
ntp-a2.nict.go. .PPS. 1 u 5 64 1 8.326 0.061 0.015
ntpq> rv
assID=0 status=c011 sync_alarm, sync_unspec, 1 event, event_restart,
version="ntpd 4.2.0a@1.1190-r Sun Aug 13 01:49:12 CDT 2006 (1)"?,
processor="i686", system="Linux/2.6.9-42.0.3.EL", leap=11, stratum=16,
precision=-16, rootdelay=0.000, rootdispersion=0.270, peer=0,
refid=INIT, reftime=00000000.00000000 Thu, Feb 7 2036 15:28:16.000,
poll=6, clock=0xc97e7e80.90a47ecf, state=1, offset=0.000,
frequency=7.054, noise=0.015, jitter=0.015, stability=0.000
ntpq> pe
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp01.so-net.ne 210.132.247.45 2 u 49 64 17 7.320 -7.920 0.157
ntp-a3.nict.go. .INIT. 16 u - 64 0 0.000 0.000 4000.00
+ntp-a3.nict.go. .PPS. 1 u 46 64 17 8.674 0.092 1.141
+ntp-a2.nict.go. .PPS. 1 u 51 64 17 8.326 0.061 0.232
ntpq> rv
assID=0 status=0654 leap_none, sync_ntp, 5 events, event_peer/strat_chg,
version="ntpd 4.2.0a@1.1190-r Sun Aug 13 01:49:12 CDT 2006 (1)"?,
processor="i686", system="Linux/2.6.9-42.0.3.EL", leap=00, stratum=3,
precision=-16, rootdelay=7.809, rootdispersion=993.819, peer=13916,
refid=210.139.246.140,
reftime=c97e7f32.b869a4df Thu, Feb 15 2007 15:41:54.720, poll=6,
clock=0xc97e7f66.09539b88, state=4, offset=-7.920, frequency=5.574,
noise=3.960, jitter=0.157, stability=47.374ntpq コマンドを用いて、NTP サーバの状態を問い合わせている。ここでは 2 回ずつ、pe と rv コマンドを実行している。1 回目の rv では sync_alarm がある。この状態ではクライアントに対して時刻情報の提供を行わない。ローカルの ntpd では、pe コマンド結果の reach が 17 になったところ*3で sync_alarm が無くなっている。
(2006-02-16T15:00 追記)ネットで ntp の設定に関する資料を検索すると、restrict 文に notrust を指定しているものがある。この指定は「時刻同期元として利用しない」というものなので、クライアントのネットワークに指定する場合が多いようだ。しかし notrust の仕様が ntp 4.2.0 から変わった*4ので、これを付けていると多くの場合にクライアントは同期が出来なくなるので注意が必要。
- 注1: 推測だけど、ntp.nict.jp のように DNS ラウンドロビンを使って IP アドレスを返していると、restrict 文と server 文で違う IP アドレスに対して設定しているとみなされるからであろう。私の設定ファイルでは
restrict default ignoreなので、特別設定していなければ server 文に書いてあろうと、そのサーバとは通信が行えなくなる。 - 注2: (2006-02-16T15:00 追記)優先的に同期する NTP サーバであって、問い合わせ間隔などは
server文の minpoll や maxpoll に依る。従って、ここの解釈は間違い。 - 注3: 正確に言うと reach は 8 ビット列を 8 進数で表示したものである。NTP サーバから正しく情報を受信できるとビットフラグが立つ。即ち 17(8) とは 1111(2) なので、4 回連続で受信に成功したことを示す。
- 注4: そのページによると「Ignore all NTP packets that are not cryptographically authenticated.」とあるため、「暗号化認証の済んでいない全ての NTP パケットを無視する」となる。従って、クライアントの認証を行えば notrust を指定していても問題はない。
Related Entries
There is not related articles.
Trackbacks
Trackback URI: http://blog.c--v.net/trackback/2007/02/15/3
There is no trackback.
There is no comment.