ubuntuでntpdateを使って時刻合わせをする

会社では、例によってProxyがあるので社内のNTPサーバに同期させる。

/etc/default/ntpdateというファイルがあったので、NTPSERVERSに社内のサーバを記述してntpdateコマンドを叩いてみる

# ntpdate
 4 Jan 11:40:08 ntpdate[23795]: no servers can be used, exiting

うまくいかない・・・

調べたらどうやら/usr/sbin/ntpdate-debianというラッパーコマンドがあるらしい。
ただしこれを使うときは、NTPDATE_USE_NTP_CONF=noにしないと設定したサーバリストが使われない。

# The settings in this file are used by the program ntpdate-debian, but not
# by the upstream program ntpdate.

# Set to "yes" to take the server list from /etc/ntp.conf, from package ntp,
# so you only have to keep it in one place.
#NTPDATE_USE_NTP_CONF=yes
NTPDATE_USE_NTP_CONF=no

# List of NTP servers to use  (Separate multiple servers with spaces.)
# Not used if NTPDATE_USE_NTP_CONF is yes.
#NTPSERVERS="ntp.ubuntu.com"
NTPSERVERS="10.x.x.x"

# Additional options to pass to ntpdate
NTPOPTIONS=""

これで上手くいきました。

# ntpdate-debian
 4 Jan 11:44:30 ntpdate[23814]: step time server 10.x.x.x offset 253.208283 sec

このntpdate-debianは起動時に実行されるらしいので気になる場合はcronで定期実行させてもいいかも。