いなほちゅんのひとりごとブログ版

私のメモ帳を公開してみる。

Raspbian on Raspberry Pi NTP Server編

Raspbian on Raspberry Pi NTP Server編
日付
カテゴリー
シェア

はじめに

初期設定編でRaspberry Piをサーバー向けにセットアップしました。
その続きということで、まずは自宅LAN内にNTPサーバーを構築してみます。
…といっても大がかりなものではなく、インターネット上で提供されているNTPサーバーと同期して自宅のLAN内にNTPサービスを提供するサーバーを構築します。

インストール

NTPサーバーはRaspbianにデフォルトでインストールされている ntp を使います。

設定

設定ファイルは /etc/ntp.conf になります。
デフォルトで指定されている pool で始まる行をコメントアウトしてその下に pool で始まる行を追記します。
また restrict で始まる行を設置するネットワークにあわせて追記します。
下記は私の環境での設定例です。

driftfile /var/lib/ntp/ntp.drift
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

pool ntp.nict.jp iburst
pool ntp.jst.mfeed.ad.jp iburst

restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict 192.168.100.0 mask 255.255.255.0 kod nomodify nopeer notrap

起動と停止

まずはNTPサービスを有効化します。

sudo systemctl enable ntp.service

NTPサービスを起動する場合は以下を実行します。

sudo systemctl start ntp.service

設定を変更してNTPサービスを再起動する場合は以下を実行します。

sudo systemctl restart ntp.service

NTPサービスを停止する場合は以下を実行します。

sudo systemctl stop ntp.service

NTPサービスを無効化する場合は以下を実行します。

sudo systemctl disable ntp.service

使い方

各システムのNTPクライアントでNTPサーバーをこのRaspberry Piに設定します。
詳しくは「<OS名> NTPクライアント」で検索すると設定の仕方が分かると思います。

おわりに

まずは比較的簡単に設定できて、PC等でしなきゃいけない変更が少ないNTPサーバーを構築してみました。
これで時刻合わせはこのRaspberry Piのみインターネットへ問い合わせて、他のPCはこのRaspberry Piに問い合わせすればよくなります。
Raspberry Piは小型で省電力なのでこの手のサーバー用途は相性抜群だと思います。
今後もいろいろとサーバー構築に挑戦してみたいと思います。

アーカイブ

タグ

ページの先頭へ