NTP

Install

Portsからインストール
# portmaster net/ntp
                                               lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
                                               x                     Options for ntp 4.2.6p2                        x
                                               x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
                                               x x            [ ] NTPSNMPD  Build and install ntpsnmpd            x x
                                               x x            [ ] RAWDCF    Enable RAWDCF option                  x x
                                               x x            [X] SSL       Enable SSL                            x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               x x                                                                x x
                                               tqmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjqu
                                               x                       [  OK  ]       Cancel                        x
                                               mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

Configure

# vi /etc/ntp.conf
#
# $FreeBSD: src/etc/ntp.conf,v 1.2.2.1.6.1 2010/12/21 17:09:25 kensmith Exp $
#
# Default NTP servers for the FreeBSD operating system.
#
# Don't forget to enable ntpd in /etc/rc.conf with:
# ntpd_enable="YES"
#
# The driftfile is by default /var/db/ntpd.drift, check
# /etc/defaults/rc.conf on how to change the location.
#

#
# The following three servers will give you a random set of three
# NTP servers geographically close to you.
# See http://www.pool.ntp.org/ for details. Note, the pool encourages
# users with a static IP and good upstream NTP servers to add a server
# to the pool. See http://www.pool.ntp.org/join.html if you are interested.
#
# The option `iburst' is used for faster initial synchronisation.
# The option `maxpoll 9' is used to prevent PLL/FLL flipping on FreeBSD.
#
#server 0.freebsd.pool.ntp.org iburst maxpoll 9
#server 1.freebsd.pool.ntp.org iburst maxpoll 9
#server 2.freebsd.pool.ntp.org iburst maxpoll 9
#server 3.freebsd.pool.ntp.org iburst maxpoll 9

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

#
# If you want to pick yourself which country's public NTP server
# you want sync against, comment out the above servers, uncomment
# the next ones and replace CC with the country's abbreviation.
# Make sure that the hostnames resolve to a proper IP address!
#
# server 0.CC.pool.ntp.org iburst maxpoll 9
# server 1.CC.pool.ntp.org iburst maxpoll 9
# server 2.CC.pool.ntp.org iburst maxpoll 9

#
# Security: Only accept NTP traffic from the following hosts.
# The following configuration example only accepts traffic from the
# above defined servers.
#
# Please note that this example doesn't work for the servers in
# the pool.ntp.org domain since they return multiple A records.
# (This is the reason that by default they are commented out)
#
#restrict default ignore
#restrict 0.pool.ntp.org nomodify nopeer noquery notrap
#restrict 1.pool.ntp.org nomodify nopeer noquery notrap
#restrict 2.pool.ntp.org nomodify nopeer noquery notrap
#restrict 127.0.0.1
#restrict -6 ::1
#restrict 127.127.1.0

restrict default ignore
restrict ntp1.jst.mfeed.ad.jp nomodify nopeer noquery notrap
restrict ntp2.jst.mfeed.ad.jp nomodify nopeer noquery notrap
restrict ntp3.jst.mfeed.ad.jp nomodify nopeer noquery notrap
restrict 127.0.0.1

restrict 192.168.1.0 mask 255.255.255.0 noquery nomodify nopeer notrap

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

driftfile /tmp/ntp.drift
手動同期
時間がずれ過ぎていると自動同期できない為、任意のNTPサーバで手動同期する。
# ntpdate ntp1.jst.mfeed.ad.jp
27 Feb 23:20:43 ntpdate[81652]: adjust time server 210.173.160.27 offset 0.001788 sec
rc.confに登録・起動
# vi /etc/rc.conf
ntpd_enable="YES"

# service ntpd start
以降はスタートアップ時に自動で起動する。

Check

同期の確認
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp1.jst.mfeed. 210.173.160.86   2 u   21   64    1   39.895   -0.096   0.002
 ntp2.jst.mfeed. 210.173.160.86   2 u   20   64    1   40.860   -0.564   0.002
 ntp3.jst.mfeed. 210.173.176.4    2 u   19   64    1   38.015    0.248   0.002
しばらくすると
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp1.jst.mfeed. 210.173.176.4    2 u   47   64   37   39.895   -0.096   5.398
*ntp2.jst.mfeed. 210.173.160.86   2 u   50   64   37   37.702   -7.374   5.776
 ntp3.jst.mfeed. 210.173.160.86   2 u   51   64   37   38.015    0.248   6.836
のようになる。
*(アスタリスク)のついてるサーバと同期している。