トップページ> "> RedHat/CentOS "> RedHat覚書

CentOS6 ntpdを起動して、インターネット上のntpサーバを参照し、時刻を同期させる

 とりあえず時刻を同期させるだけなら、こんな感じ。rootで実行する必要がある。

 (前提として、インターネットに接続できる環境である必要がある)

[root@localhost Desktop]# service ntpd start
ntpd を起動中:                                             [  OK  ]
[root@localhost Desktop]#
[root@localhost Desktop]#
[root@localhost Desktop]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 kazunoko.kuee.k 210.173.160.27   3 u    3   64    1   34.277  -399473   0.000
 laika.paina.jp  203.178.137.183  2 u    2   64    1   45.715  -399481   0.000
 ntp.kiba.net    220.61.24.151    2 u    1   64    1   42.465  -399484   0.000

 service ntpd start でntpデーモンを起動すると、デフォルトで設定されているインターネット上のntpサーバに時刻同期をしにいってくれる。

 ntpq -p というコマンドは、時刻同期をしている対象サーバをずらりと表示させるためのコマンドだ。

ローカルネットワーク内のntpサーバに時刻同期させたい場合の設定

 設定ファイルは、/etc/ntp.confだ。

 とりあえずファイルをいじる前に、

cd /etc
cp ntp.conf  ntp.conf.org

とかやって、オリジナルのファイルをバックアップしておくといいだろう。

 ntp.confのどのへんに追加してもいいんだけども、私はなんとなく、以下の位置にntpサーバ指定を追加した。(赤字部分

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org

#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient   # broadcast client
#broadcast 224.0.1.1 autokey  # multicast server
#multicastclient 224.0.1.1  # multicast client
#manycastserver 239.255.254.254  # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10 

server 192.168.1.1  ←ローカルサーバ 192.168.1.1に時刻同期しにいく設定

 ntp.confを書き換えたら、ntpdを再起動しよう。

[root@localhost Desktop]# service ntpd restart
ntpd を停止中:                                             [  OK  ]
ntpd を起動中:                                             [  OK  ]
[root@localhost Desktop]#

自サーバをntpサーバにしたいときの設定

 192.168.1.xxというIPアドレスのマシンからntp問い合わせを許可する場合は、以下の赤字部分を追加する。

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org

#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient   # broadcast client
#broadcast 224.0.1.1 autokey  # multicast server
#multicastclient 224.0.1.1  # multicast client
#manycastserver 239.255.254.254  # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10 

 nomodify notrapという指定は、外部から勝手に時刻を変えられるようなイタズラをされないため、というか、そんな感じのオプション指定のようだ。

 そんな感じ。暗号化鍵を使った、よりセキュアな時刻同期も出来るらしいが、それはまたそのうち試して見ることにして、今回はこのへんでntp関連の覚書を終わる。

  はてなブックマーク - CentOS6 ntpdを起動して、インターネット上のntpサーバを参照し、時刻を同期させる この記事にTwitterでつぶやく このページをはてなブックマーク
次のsnmp情報をまとめてゲットする snmpwalkへ
トップページ> "> RedHat/CentOS "> RedHat覚書 もくじ