NTPとは
NTPとはサーバの内部時計をネットワーク経由で同期をとり、時刻調整をするものです。自宅サーバでメールサーバなどを稼働させる場合は時刻は必ず正しい必要がありますので
NTPを導入して、時刻を調整しましょう。
インストール
APTよりインストールを行います。
# sudo aptitude update
# sudo aptitude install ntp
# sudo aptitude install ntp
設定
NTPはインストールするだけで基本的な設定が完了しているのですがデフォルトで参照するサーバが海外のサーバなので、日本の独立行政法人のサーバを追加します。
まず設定ファイルを開き
# sudo vim /etc/ntp.conf
以下を書き加えます。■ サーバの追加
NTPが参照するサーバの追加(独立行政法人情報通信研究機構のサーバ)
#19行目付近
server ntp.nict.jp
server ntp.nict.jp
■ アクセスの許可
情報通信機構のサーバ(同じアドレスで4つのIPを持っています)への許可
#37行目付近
restrict 133.243.238.163 mask 255.255.255.255 nomodify notrap noquery
restrict 133.243.238.164 mask 255.255.255.255 nomodify notrap noquery
restrict 133.243.238.243 mask 255.255.255.255 nomodify notrap noquery
restrict 133.243.238.244 mask 255.255.255.255 nomodify notrap noquery
これで設定は完了です。サーバを再起動させます。restrict 133.243.238.163 mask 255.255.255.255 nomodify notrap noquery
restrict 133.243.238.164 mask 255.255.255.255 nomodify notrap noquery
restrict 133.243.238.243 mask 255.255.255.255 nomodify notrap noquery
restrict 133.243.238.244 mask 255.255.255.255 nomodify notrap noquery
# sudo /etc/init.d/ntp start
動作確認
NTPが同期をとるまで多少時間がかかるので少し待ちます。・・・
・・
・
次のコマンドを打ちます
# ntpq -pn
そうすると以下のように表示されるはずです。remote refid st t when poll reach delay offset jitter ============================================================================== *133.243.238.244 .PPS. 1 u 26 64 377 10.434 -7.702 1.990 -217.114.97.98 130.88.200.6 3 u 54 64 377 294.312 -29.386 1.702 +64.34.193.47 216.162.200.152 2 u 43 64 377 196.823 1.176 2.092 +62.66.254.154 192.36.144.23 2 u 19 64 377 313.693 2.879 1.328 -216.234.161.11 68.216.79.113 2 u 16 64 377 132.532 6.782 1.086
後は自動で時刻あわせを行ってくれます。