ユーザ用ツール

サイト用ツール


サイドバー

Index

はじめてのおつかい






DokuWiki整形記法


PlayGround



os:freebsd:ntp:ntpconf

ntpの設定

まずは時刻合わせ

ntpdは時刻が一定以上狂っていると同期しません。
そこで、ntpdateで強制的に時刻合わせをします。

# ntpdate ntp.nict.jp
 n May HH:MM:SS ntpdate[.....]: step time server www.xxx.yyy.zzz offset -39.865823 sec

「ntp.conf」の設定

mfeed

複数設定が可能な場合

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

1つのみ設定が可能な場合

ntp.jst.mfeed.ad.jp

IPv6

ntp1.v6.mfeed.ad.jp (2001:3a0:0:2001::27:123)
ntp2.v6.mfeed.ad.jp (2001:3a0:0:2005::57:123)
ntp3.v6.mfeed.ad.jp (2001:3a0:0:2006::87:123)

NICT

ここでは、NICTのサーバを使用します。
以下の行を設定ファイル(/etc/ntp.conf)に追加します。1)

pool ntp.nict.jp

ちなみに、ntpのサーバ設定はホスト名で設定することが、should(するべき)となっています。

以前のバージョンでは

server -4 ntp.nict.jp iburst
server -4 ntp.nict.jp iburst
server -4 ntp.nict.jp iburst

同じ内容を3行書く

「rc.conf」の設定

起動時にntpが自動的に起動されるよう、/etc/rc.confに以下の記述を追記します。

ntpd_enable="YES"

起動

手動で起動する場合は以下のコマンドです。
# /etc/rc.d/ntpd start

# service ntpd start

動作確認

ntpqを利用することで、動作確認できます。

$ ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp-a3.nict.go. .NICT.           1 u   30   64   37    2.812  148.451  86.865
*ntp-a2.nict.go. .NICT.           1 u   38   64   37    2.536  129.673  86.992
+ntp-b3.nict.go. .NICT.           1 u   23   64   37    4.308  151.918  85.691

ハードウェアクロックの設定

ntpdはハードウェアクロックまでは設定しませんので、このままでは再起動時に再び時刻が狂ってしまいます。
ハードウェアクロックを設定するためにはntpdateを使用します。2)

起動時にntpdate

ntpdate_enable="YES"
ntpdate_flags="-b ntp1.jst.mfeed.ad.jp"

crontabでntpdate

0       12      *       *       *       /usr/sbin/ntpdate ntp.nict.jp

2017.04.14 注:再起動時に時計が変わる場合以下に注意

/etc/wall_cmos_clock このファイルがあると、CMOSクロックがローカル時間に設定されていることを示し、反対にこれが存在しないと、 UTC の CMOS クロックに設定されています。

おまけ

ntpdが動作中はntpdateは動作しません。 こんな場合は、

# ntpdate -bu ntp.nict.jp

でOK。

アクセス制限

すでに古い内容です。最新の情報を参照ください

バージョンによってはNTPリフレクション攻撃などに利用される場合があるので、適切なアクセス制限を行っておくべきです。 対策としては、ntp.conf 内に「restrict」を追加してアクセス制限を行う、「disable monitor」を追加して monlist 機能を無効にするなどがあります。 【restrict の設定例】

restrict default ignore
restrict -6 default ignore
restrict 127.0.0.1
restrict 192.168.xxx.0 mask 255.255.255.0 nopeer nomodify notrap

# 外部のNTPサーバ
# NICTやMFEEDはラウンドロビンのため全て記述する
restrict 210.173.160.57 nomodify notrap noquery
restrict 210.173.160.87 nomodify notrap noquery
restrict 210.173.160.27 nomodify notrap noquery
restrict 133.243.238.163 nomodify notrap noquery
restrict 133.243.238.164 nomodify notrap noquery
restrict 133.243.238.243 nomodify notrap noquery
restrict 133.243.238.244 nomodify notrap noquery

# 外部のNTPサーバ
server ntp.jst.mfeed.ad.jp
server ntp.nict.jp

NICTなどでは、restrictよりファイアウォールの導入が勧められている

1)
バージョン 4.2.6 以降
2)
linuxの場合はhwclock
os/freebsd/ntp/ntpconf.txt · 最終更新: 2019/12/16 16:21 by hayashi