LoginSignup
14
15

More than 5 years have passed since last update.

内部向けのntpdサーバの設定

Last updated at Posted at 2018-08-16

検証環境

OS:RHEL6.10

概要

  • 自組織の検証環境用にRHEL6.10でNTPサーバを構築
  • OCNのNTPサーバと時刻同期する
  • 検証環境の他のサーバとNTP動機をする

まずは手動で時刻設定

ntpdateコマンドで手動でのntpとの同期

  • NTPが起動していれば停止する
# service ntpd stop
  • ntpdateコマンドでNICTのntpサーバから時刻合わせを実施
# ntpdate -d ntp.nict.jp
10 Aug 13:18:33 ntpdate[15259]: adjust time server 133.243.238.244 offset -0.000366 sec

ハードウェアクロック(マザーボード上の時計)の設定

  • 現在のハードウェアクロックを表示
# hwclock --show
  • ハードウェアクロックとLinuxのシステムクロックの差分を確認する
# hwclock --show ; date
2018年08月10日 13時20分37秒  -0.719122 秒
2018年  8月 10日 金曜日 13:20:13 JST
  • ハードウェアクロックを現在のシステム・クロックに合わせる。
# hwclock --systohc
  • 時刻差分がなくなったことを確認する
# hwclock --show ; date
2018年08月10日 13時21分15秒  -0.391008 秒
2018年  8月 10日 金曜日 13:21:15 JST
  • ntpdate実行時にハードウェアクロックをシンクロさせる設定をする
# vim /etc/sysconfig/ntpdate
-----------
SYNC_HWCLOCK=yes
-----------

内部向けのNTPサーバの設定

/etc/ntp.confの編集

# vim /etc/ntp.conf
  • 設定項目解説
ignore  すべてのNTPパケットを無視    restrict <対象NTPサーバー> ignore
nomodify    時刻問い合わせに応答するが、時刻の変更要求などは無視  restrict <対象NTPサーバー> nomodify
notrust 時刻問い合わせに応答するが、自身の時刻合わせには使用しない restrict <対象NTPサーバー> notrust
nopeer  指定ホストと相互に同期しない  restrict <対象NTPサーバー> nopeer
noquery NTPの実装に依存する時刻問い合わせを無視   restrict <対象NTPサーバー> noquery

上記項目に沿って/etc/ntp.confの設定項目を記述していく↓

  • 全てのNTP通信を拒否(この後ろに許可するACLを記載する)
restrict default ignore
restrict -6 default ignore
  • ローカルホストからのNTP通信を許可する
restrict -4 127.0.0.1
restrict -6 ::1
  • 組織内private networkセグメントからの時刻問い合わせのみに応答する
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.3.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.200.0 mask 255.255.255.0 nomodify notrap
  • 上位NTPサーバへの通信を限定する
restrict ntp-tk01.ocn.ad.jp nomodify
restrict ntp-tk02.ocn.ad.jp nomodify
restrict ntp-os01.ocn.ad.jp nomodify
  • 上位NTPサーバ指定
server ntp-tk01.ocn.ad.jp
server ntp-tk02.ocn.ad.jp
server ntp-os01.ocn.ad.jp
  • その他の設定 driftfile /var/lib/ntp/drift ### ntpdにより作成される誤差修正値ファイルの指定。 broadcastdelay 0.008     ### ブロードキャストで生じる誤差を指定。
authenticate yes ### ntpdの認証システムを利用する。

keys      /etc/ntp/keys  ### ntpdの認証システムを利用する場合のキーファイルを指定。

logfile /var/log/ntp/ntp.log ### logの出力先を指定

ntpサーバの起動

  • logファイルの作成、パーミッション変更
touch /var/log/ntp/ntp.log
chown ntp:ntp /var/log/ntp/ntp.log
  • ntpdサービスを起動する # service ntpd start # chkconfig ntpd on

NTPサーバとの同期状態の確認

# ntpq -p
remote  タイムサーバ名と、そのサーバがどのような立場にあるかを表示します。
refid   remote がどこから時刻を同期しているかを表します。不明の場合は 0.0.0.0 を示します。
st  サーバの階層を示す stratum 番号が表示されます。一般に、この番号が大きくなるほど、時間の信頼性が薄らいでいきます。
t   階層の種類です。( l: local, u: unicast, m: multicast, b:broadcast )
when    remote から最後にパケットを受け取ってからの時間です。
poll    ポーリング間隔を表示します。
reach   到達可能レジスタデータを8進数で示すそうです。
delay   時間の遅延見積もりをミリ秒単位で表示します。
offset  remote との時刻のずれをミリ秒単位で表示します。
jitter  remote の分散 (ばらつき) をミリ秒単位で表示するそうです。
  • 下記の用になっていれば同期OK
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp-tk01.ocn.ad 210.173.160.27   3 u   92 1024  377    5.809   -0.345   1.200
*ntp-tk02.ocn.ad 210.173.160.57   3 u 1008 1024  377    6.077   -0.538   0.517
+ntp-os01.ocn.ad 210.173.160.27   3 u  726 1024  377   13.946    0.508   1.827

参考URLにさせていただいたサイト

14
15
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
14
15