(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【Linux】ntp.confの設定変更がntpdに反映されない時の解決策

スポンサーリンク

事象

/etc/ntp.confにて設定を以下のように変更して

server ntp.jst.mfeed.ad.jp

ntpサービスを再起動しても設定が反映されない。

コマンド実行環境
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"

原因/解決策

原因

ntpdの起動時に読まれている設定ファイルが/etc/ntp.confではない

解決策

該当の設定ファイルに対して修正を行う。
以下、補足です。

補足

Debian環境では以下コマンドにてntpサービスが確認できます。

# systemctl status ntp
● ntp.service - LSB: Start NTP daemon
   Loaded: loaded (/etc/init.d/ntp; generated; vendor preset: enabled)
   Active: active (running) since ...
     Docs: man:systemd-sysv-generator(8)
  Process: 28475 ExecStop=/etc/init.d/ntp stop (code=exited, status=0/SUCCESS)
  Process: 28484 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS)
    Tasks: 2 (limit: 4915)
   Memory: 852.0K
      CPU: 15ms
   CGroup: /system.slice/ntp.service
           mq28497 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -c /run/ntp.conf.dhcp -u 106:110

上記を見れば分かりますが設定ファイルは/etc/ntp.confではなく/run/ntp.conf.dhcpを読んでいます。

よって該当のファイルを修正し

# /etc/init.d/ntp restart

または

# systemctl status ntp

で再起動すれば以下のようにNTPサーバの宛先修正が反映されています。

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp3.jst.mfeed. 133.243.236.19   2 u   38   64  377  157.948   -0.543   0.275

同様の状況にある方はntpの設定ファイルがデフォルトから変更されている可能性を考慮してみてください。

# ps -aux | grep ntp
ntp   xxx  Ssl  10:40   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -c /run/ntp.conf.dhcp -u 106:110

以上、ご参考になれば幸いです。