2016年12月12日月曜日

FreeBSD 11でntpdを設定する

FreeBSD 11でntpdを設定するには以下のようにします。/etc/ntp/confに以下のような記述があります。
# cat /etc/ntp.conf

#
# If a server loses sync with all upstream servers, NTP clients
# no longer follow that server. The local clock can be configured
# to provide a time source when this happens, but it should usually
# be configured on just one server on a network. For more details see
# http://support.ntp.org/bin/view/Support/UndisciplinedLocalClock
# The use of Orphan Mode may be preferable.
#
#server 127.127.1.0
#fudge 127.127.1.0 stratum 10
これに従って、末尾に以下の設定を加えます。
server 127.127.1.0
fudge 127.127.1.0 stratum 10
次に、参照するNTPサーバーを設定します。
デフォルトでは、
server 0.freebsd.pool.ntp.org iburst
server 1.freebsd.pool.ntp.org iburst
server 2.freebsd.pool.ntp.org iburst
#server 3.freebsd.pool.ntp.org iburst
とあり、FreeBSD用のNTPサーバーがあるようです。ただ、これらは海外にあるものもあるようなので、ネットワーク的に近いサーバーを利用するようにします。

まずNICTのNTPサーバーの設定を確認します。
[Q.1-1]     設定方法を教えてください。
http://jjy.nict.go.jp/tsp/PubNtp/qa.html#q1-1

ntpd の場合 (Linux や FreeBSD など)
/etc/ntp.conf に次の1行を加えてください。
pool ntp.nict.jp

バージョン 4.2.6 以降をご利用ください。
これに従って設定をします。
次にインターネットマルチフィードの利用法を確認します。
NTPの使い方
http://www.jst.mfeed.ad.jp/about/04.html
UNIX (Linuxなど) の場合

www.ntp.org で配布されているntpdが利用出来ます。ntp.confに以下のようにご記述ください。
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp
指定方法にpoolとserverの違いがあります。man ntp.confで調べてみました。
Configuration Commands
     The various modes are determined by the command keyword and the type of
     the required IP address.  Addresses are classed by type as (s) a remote
     server or peer (IPv4 class A, B and C), (b) the broadcast address of a
     local interface, (m) a multicast address (IPv4 class D), or (r) a
     reference clock address (127.127.x.x).  
     …
     pool    For type s addresses, this command mobilizes a persistent client
             mode association with a number of remote servers.  In this mode
             the local clock can synchronized to the remote server, but the
             remote server can never be synchronized to the local clock.

     server  For type s and r addresses, this command mobilizes a persistent
             client mode association with the specified remote server or local
             radio clock.  In this mode the local clock can synchronized to
             the remote server, but the remote server can never be
             synchronized to the local clock.  This command should not be used
             for type b or m addresses.
poolだとそのアドレスで指定した複数のサーバー、serverは指定した1つのサーバーを参照するようです。調べてみると、以下のような説明を見つけました。
NTPサーバの設定
http://vogel.at.webry.info/201501/article_5.html

インターネットマルチフィード (MFEED)の NTPサーバ ntp.jst.mfeed.ad.jp を指定する場合、

server ntp.jst.mfeed.ad.jp

とすると、ntp.jst.mfeed.ad.jp はDNSラウンドロビンによって以下のいずれかが選択されます。
このように、上位NTPサーバ側では、複数台のNTPサーバに負荷分散をさせることが出来ます。

ntp1.jst.mfeed.ad.jp
ntp2.jst.mfeed.ad.jp
ntp3.jst.mfeed.ad.jp

一方、server行では無く、pool行でも上位NTPサーバを指定できます。

pool ホスト名

pool行に指定した場合は、DNSラウンドロビンの全てのサーバを指定したことと同等になります。
例えば、独立行政法人情報通信研究機構 (NICT)のNTPサーバ ntp.nict.jp を指定します。

pool ntp.nict.jp

これは、下記と同等の設定になります。
server ntp-b3.nict.go.jp
server ntp-a2.nict.go.jp
server ntp-a3.nict.go.jp
server ntp-b2.nict.go.jp

同様に、

pool ntp.jst.mfeed.ad.jp

とすると、下記と同等になります。

server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp
今回の設定では、それぞれのサイトの説明の通りに記述することにします。