Ubuntu

Ubuntu 12.04 サーバー再構築(15) NTPとして動作させる

忘れてた・・・NTPとして動作させるつもりだったことを。

独立行政法人 情報通信研究機構が提供しているサービスを利用させていただくことにする。時空標準研究室にサーバーに関する説明がある。

設定にあたっては自宅サーバ構築備忘録を参考にさせていただいた。manを読んでもrestrictに関しての説明が見当たらず、ntp.confのコメント通りに設定してもサーバーとして動作しなくて困ったので、大変助かった。

広告


Firewallの設定で、 123/udpを開けておく。

ntpを導入する。

$ sudo apt-get install ntp

ntpを設定する。

/etc/ntp.conf

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift


# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#server 0.ubuntu.pool.ntp.org
#server 1.ubuntu.pool.ntp.org
#server 2.ubuntu.pool.ntp.org
#server 3.ubuntu.pool.ntp.org
server ntp.nict.jp

# Use Ubuntu's ntp server as a fallback.
#server ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page 
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
restrict 172.16.0.0 mask 255.255.0.0

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

ntpを再起動する。

$ sudo service ntp restart


サーバーとの時刻同期ができているか確認する。

ntp.nict.jpと同期ができていない状態。

$ ntpq -p
$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp-a3.nict.go. .NICT.           1 u    6   64    3   10.971   -2.172   0.148

ntp.nict.jpと同期ができた状態。

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp-b2.nict.go. .NICT.           1 u   15   64  177   12.423  -47.426  16.321


ntp.nict.jpと同期ができているようなので、サーバーとして動作するようになっているか確認するため、他のLinuxやWindowsなどから同期してみる。

Linuxからの場合は以下。

$ sudo ntpdate hogeserver.hogeddns.jp
16 Jun 07:44:29 ntpdate[4354]: adjust time server 172.16.nnn.nnn offset 0.146837 sec

同期ができていない場合は、以下の様なエラーが発生する。

$ sudo ntpdate hogeserver.hogeddns.jp
16 Jun 07:38:21 ntpdate[4341]: no server suitable for synchronization found

Windows7の場合は、タスクバーの通知領域に表示されている時計を右クリックし表示されるメニューから「日付と時刻の調整」を選択。日付と時刻ダイアログが表示されるので「インターネット時刻」タブをクリック、「設定の変更」ボタンをクリックする。サーバーとしてhogeserver.hogeddns.jpを入力し、「今すぐ更新」ボタンをクリックする。

広告
ろっひー

コメントはこちらから お気軽にどうぞ ~ 投稿に関するご意見・感想・他